Add .gitattributes
This commit is contained in:
parent
a77e0cc472
commit
d535b758d4
38
.gitattributes
vendored
Normal file
38
.gitattributes
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
# Handle line endings automatically for files detected as text
|
||||
# and leave all files detected as binary untouched.
|
||||
* text=auto
|
||||
|
||||
#
|
||||
# The above will handle all files NOT found below
|
||||
#
|
||||
# These files are text and should be normalized (Convert crlf => lf)
|
||||
*.css text
|
||||
*.df text
|
||||
*.htm text
|
||||
*.html text
|
||||
*.java text
|
||||
*.js text
|
||||
*.json text
|
||||
*.jsp text
|
||||
*.jspf text
|
||||
*.properties text
|
||||
*.sh text
|
||||
*.sql text
|
||||
*.svg text
|
||||
*.tld text
|
||||
*.txt text
|
||||
*.xml text
|
||||
|
||||
# These files are binary and should be left untouched
|
||||
# (binary is a macro for -text -diff)
|
||||
*.class binary
|
||||
*.dll binary
|
||||
*.ear binary
|
||||
*.gif binary
|
||||
*.ico binary
|
||||
*.jar binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.png binary
|
||||
*.so binary
|
||||
*.war binary
|
86
.gitignore
vendored
86
.gitignore
vendored
@ -1,46 +1,46 @@
|
||||
# Compiled source #
|
||||
###################
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack these files and commit the raw source
|
||||
# git has its own built in compression methods
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
|
||||
# Logs and databases #
|
||||
######################
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store*
|
||||
ehthumbs.db
|
||||
Icon?
|
||||
Thumbs.db
|
||||
|
||||
# folders #
|
||||
###########
|
||||
bin/
|
||||
target/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
||||
config.yml
|
||||
# Compiled source #
|
||||
###################
|
||||
*.com
|
||||
*.class
|
||||
*.dll
|
||||
*.exe
|
||||
*.o
|
||||
*.so
|
||||
|
||||
# Packages #
|
||||
############
|
||||
# it's better to unpack these files and commit the raw source
|
||||
# git has its own built in compression methods
|
||||
*.7z
|
||||
*.dmg
|
||||
*.gz
|
||||
*.iso
|
||||
*.jar
|
||||
*.rar
|
||||
*.tar
|
||||
*.zip
|
||||
|
||||
# Logs and databases #
|
||||
######################
|
||||
*.log
|
||||
*.sql
|
||||
*.sqlite
|
||||
|
||||
# OS generated files #
|
||||
######################
|
||||
.DS_Store*
|
||||
ehthumbs.db
|
||||
Icon?
|
||||
Thumbs.db
|
||||
|
||||
# folders #
|
||||
###########
|
||||
bin/
|
||||
target/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
||||
config.yml
|
||||
src/com/matejdro/
|
||||
/dependency-reduced-pom.xml
|
||||
/global.yml
|
||||
|
130
README.md
130
README.md
@ -1,66 +1,66 @@
|
||||
[Jail 3.0](http://ci.graywolf336.com/job/Jail/)
|
||||
====
|
||||
This plugins adds Jail to your Minecraft server. Admins can define several jails and then jail/unjail people or jail them on time basis. Plugin also offers wide variety of protections, so players won't escape out of your jail.
|
||||
|
||||
**All mysql queries and actions are done sync, meaning if the connection to the mysql server is slow/down this will probably end up blocking the server. There are plans to change this, as we don't want to slow down anyone's servers.**
|
||||
|
||||
[![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/)
|
||||
|
||||
Beta 2 Changes
|
||||
===
|
||||
*Changes since Beta 1*
|
||||
* Using UUID as the only means of knowing if someone is jailed or not, last known username is stored for commands
|
||||
* Jailings via jail sticks are now recorded, [#20](https://github.com/graywolf336/Jail/issues/20)
|
||||
* Fix the default Jail Stick not being loaded correctly, [#21](https://github.com/graywolf336/Jail/issues/21)
|
||||
* Implement Scoreboards, with title and time configurable. ([#15](https://github.com/graywolf336/Jail/issues/15))
|
||||
* Implemented Jail Pay [#11](https://github.com/graywolf336/Jail/issues/11)
|
||||
* Convert old data and config values, only some are done and if you don't want the old data delete your `global.yml`
|
||||
* Add config option to disallow the usage of Jail Sticks
|
||||
* Added `/jail time` for easy access to adding/subtracting time - [Bukkit Dev Ticket #432](http://dev.bukkit.org/bukkit-plugins/jail/tickets/432/)
|
||||
* Added `/togglejaildebug` for easily toggling the debugging state, enable if you have a problem and want to send me information
|
||||
*
|
||||
|
||||
Beta 1 Changes
|
||||
===
|
||||
*Changes since alpha*
|
||||
* MySQL storage is now a valid option for storage ([#18](https://github.com/graywolf336/Jail/issues/18))
|
||||
* MySQL data validation, basically if a cell or prisoner reference a jail which no longer exists they are removed
|
||||
* Fix a bug with not being able to unjail someone forcefully if they were in a cell ([#17](https://github.com/graywolf336/Jail/issues/17))
|
||||
* Add the record keeping system ([#12](https://github.com/graywolf336/Jail/issues/12))
|
||||
* Added Jail Sticks, format of them has slightly changed ([#16](https://github.com/graywolf336/Jail/issues/16))
|
||||
|
||||
Changes
|
||||
===
|
||||
*With this being version 3 of this plugin, a couple things have changed but the core concept is still the exact same. Here are some drastic changes:*
|
||||
* Time can now be entered different formats, 3hours or 15mins or 4days
|
||||
* New language system
|
||||
* New config system (per jail configs are going to make a come back)
|
||||
* Items in the config use item names now, **not** the ids
|
||||
* All commands are prevented by default, now there is **only** a whitelist
|
||||
* All interactions are prevented by default, add to the whitelist what you want
|
||||
* If store inventory is not enabled, inventories are deleted upon jailing
|
||||
* Sign text has a new format, old format will not be converted
|
||||
* Max reason length has been removed, might be added back in if needed
|
||||
|
||||
ToDo
|
||||
===
|
||||
* Jail pay
|
||||
* Jail set
|
||||
* Jail vote
|
||||
* Jailing for swearing
|
||||
* Guards (PlayerMoveProtectionAction - when they try to move do we teleport them back, let the guards get them, or nothing)
|
||||
* Storing permissions
|
||||
* Update Notifications
|
||||
* Pages on jail list
|
||||
|
||||
Notice
|
||||
===
|
||||
* If you ran an alpha or beta, please delete the en.yml so that you get the additional messages added since your version (will update in the future)
|
||||
* Old messages (language) will not be converted
|
||||
* MaximumAFKTime setting will not convert over, the format isn't clear and the old version didn't provide a way to get values with decimal places
|
||||
* EnableLogging has been removed, we are always going to be logging (unless major request to control this)
|
||||
* Prisoner's old inventory strings in the database are lost, we can not convert those
|
||||
* Prisoner's Previous Position is not converted.
|
||||
|
||||
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
|
||||
[Jail 3.0](http://ci.graywolf336.com/job/Jail/)
|
||||
====
|
||||
This plugins adds Jail to your Minecraft server. Admins can define several jails and then jail/unjail people or jail them on time basis. Plugin also offers wide variety of protections, so players won't escape out of your jail.
|
||||
|
||||
**All mysql queries and actions are done sync, meaning if the connection to the mysql server is slow/down this will probably end up blocking the server. There are plans to change this, as we don't want to slow down anyone's servers.**
|
||||
|
||||
[![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/)
|
||||
|
||||
Beta 2 Changes
|
||||
===
|
||||
*Changes since Beta 1*
|
||||
* Using UUID as the only means of knowing if someone is jailed or not, last known username is stored for commands
|
||||
* Jailings via jail sticks are now recorded, [#20](https://github.com/graywolf336/Jail/issues/20)
|
||||
* Fix the default Jail Stick not being loaded correctly, [#21](https://github.com/graywolf336/Jail/issues/21)
|
||||
* Implement Scoreboards, with title and time configurable. ([#15](https://github.com/graywolf336/Jail/issues/15))
|
||||
* Implemented Jail Pay [#11](https://github.com/graywolf336/Jail/issues/11)
|
||||
* Convert old data and config values, only some are done and if you don't want the old data delete your `global.yml`
|
||||
* Add config option to disallow the usage of Jail Sticks
|
||||
* Added `/jail time` for easy access to adding/subtracting time - [Bukkit Dev Ticket #432](http://dev.bukkit.org/bukkit-plugins/jail/tickets/432/)
|
||||
* Added `/togglejaildebug` for easily toggling the debugging state, enable if you have a problem and want to send me information
|
||||
*
|
||||
|
||||
Beta 1 Changes
|
||||
===
|
||||
*Changes since alpha*
|
||||
* MySQL storage is now a valid option for storage ([#18](https://github.com/graywolf336/Jail/issues/18))
|
||||
* MySQL data validation, basically if a cell or prisoner reference a jail which no longer exists they are removed
|
||||
* Fix a bug with not being able to unjail someone forcefully if they were in a cell ([#17](https://github.com/graywolf336/Jail/issues/17))
|
||||
* Add the record keeping system ([#12](https://github.com/graywolf336/Jail/issues/12))
|
||||
* Added Jail Sticks, format of them has slightly changed ([#16](https://github.com/graywolf336/Jail/issues/16))
|
||||
|
||||
Changes
|
||||
===
|
||||
*With this being version 3 of this plugin, a couple things have changed but the core concept is still the exact same. Here are some drastic changes:*
|
||||
* Time can now be entered different formats, 3hours or 15mins or 4days
|
||||
* New language system
|
||||
* New config system (per jail configs are going to make a come back)
|
||||
* Items in the config use item names now, **not** the ids
|
||||
* All commands are prevented by default, now there is **only** a whitelist
|
||||
* All interactions are prevented by default, add to the whitelist what you want
|
||||
* If store inventory is not enabled, inventories are deleted upon jailing
|
||||
* Sign text has a new format, old format will not be converted
|
||||
* Max reason length has been removed, might be added back in if needed
|
||||
|
||||
ToDo
|
||||
===
|
||||
* Jail pay
|
||||
* Jail set
|
||||
* Jail vote
|
||||
* Jailing for swearing
|
||||
* Guards (PlayerMoveProtectionAction - when they try to move do we teleport them back, let the guards get them, or nothing)
|
||||
* Storing permissions
|
||||
* Update Notifications
|
||||
* Pages on jail list
|
||||
|
||||
Notice
|
||||
===
|
||||
* If you ran an alpha or beta, please delete the en.yml so that you get the additional messages added since your version (will update in the future)
|
||||
* Old messages (language) will not be converted
|
||||
* MaximumAFKTime setting will not convert over, the format isn't clear and the old version didn't provide a way to get values with decimal places
|
||||
* EnableLogging has been removed, we are always going to be logging (unless major request to control this)
|
||||
* Prisoner's old inventory strings in the database are lost, we can not convert those
|
||||
* Prisoner's Previous Position is not converted.
|
||||
|
||||
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
|
||||
====
|
||||
|
436
pom.xml
436
pom.xml
@ -1,219 +1,219 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.graywolf336</groupId>
|
||||
<artifactId>Jail</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<name>Jail</name>
|
||||
<description>Ban too harsh? Mute too weak? Kicking not enough? Jail them! </description>
|
||||
<url>http://dev.bukkit.org/bukkit-plugins/jail/</url>
|
||||
<ciManagement>
|
||||
<url>http://ci.graywolf336.com/job/Jail/</url>
|
||||
<system>jenkins</system>
|
||||
</ciManagement>
|
||||
<issueManagement>
|
||||
<url>http://dev.bukkit.org/bukkit-plugins/jail/tickets/</url>
|
||||
<system>Dev Bukkit</system>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<url>https://github.com/graywolf336/Jail</url>
|
||||
<connection>scm:git:git://github.com/graywolf336/Jail.git</connection>
|
||||
<developerConnection>scm:git:git:@github.com/graywolf336/Jail.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.9-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>5.5.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.27-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.lexicalscope.jewelcli</groupId>
|
||||
<artifactId>jewelcli</artifactId>
|
||||
<version>0.8.9</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.carrotsearch</groupId>
|
||||
<artifactId>junit-benchmarks</artifactId>
|
||||
<version>0.7.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- End of Test Dependencies -->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<!-- <sourceDirectory>${basedir}/src</sourceDirectory> -->
|
||||
<defaultGoal>clean install test</defaultGoal>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<!-- Plugins -->
|
||||
<plugins>
|
||||
<!-- Compile plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Jar Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries />
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.lexicalscope.jewelcli:jewelcli</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.11</version>
|
||||
<configuration>
|
||||
<parallel>methods</parallel>
|
||||
<threadCount>10</threadCount>
|
||||
<excludes>
|
||||
<exclude>**/TestCommandSender.java</exclude>
|
||||
<exclude>**/TestInstanceCreator.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-junit47</artifactId>
|
||||
<version>2.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>repo-release</id>
|
||||
<name>repo.graywolf336.com Releases</name>
|
||||
<url>http://repo.graywolf336.com/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>repo-snapshot</id>
|
||||
<name>repo.graywolf336.com Snapshots</name>
|
||||
<url>http://repo.graywolf336.com/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.graywolf336</groupId>
|
||||
<artifactId>Jail</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<name>Jail</name>
|
||||
<description>Ban too harsh? Mute too weak? Kicking not enough? Jail them! </description>
|
||||
<url>http://dev.bukkit.org/bukkit-plugins/jail/</url>
|
||||
<ciManagement>
|
||||
<url>http://ci.graywolf336.com/job/Jail/</url>
|
||||
<system>jenkins</system>
|
||||
</ciManagement>
|
||||
<issueManagement>
|
||||
<url>http://dev.bukkit.org/bukkit-plugins/jail/tickets/</url>
|
||||
<system>Dev Bukkit</system>
|
||||
</issueManagement>
|
||||
<scm>
|
||||
<url>https://github.com/graywolf336/Jail</url>
|
||||
<connection>scm:git:git://github.com/graywolf336/Jail.git</connection>
|
||||
<developerConnection>scm:git:git:@github.com/graywolf336/Jail.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/content/groups/public</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sk89q-repo</id>
|
||||
<url>http://maven.sk89q.com/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.9-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.9-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldedit</artifactId>
|
||||
<version>5.5.7-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>Vault</artifactId>
|
||||
<version>1.2.27-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.lexicalscope.jewelcli</groupId>
|
||||
<artifactId>jewelcli</artifactId>
|
||||
<version>0.8.9</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Start of Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-easymock</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.carrotsearch</groupId>
|
||||
<artifactId>junit-benchmarks</artifactId>
|
||||
<version>0.7.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- End of Test Dependencies -->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<!-- <sourceDirectory>${basedir}/src</sourceDirectory> -->
|
||||
<defaultGoal>clean install test</defaultGoal>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
|
||||
<!-- Plugins -->
|
||||
<plugins>
|
||||
<!-- Compile plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Jar Plugin -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries />
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.lexicalscope.jewelcli:jewelcli</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.11</version>
|
||||
<configuration>
|
||||
<parallel>methods</parallel>
|
||||
<threadCount>10</threadCount>
|
||||
<excludes>
|
||||
<exclude>**/TestCommandSender.java</exclude>
|
||||
<exclude>**/TestInstanceCreator.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-junit47</artifactId>
|
||||
<version>2.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>repo-release</id>
|
||||
<name>repo.graywolf336.com Releases</name>
|
||||
<url>http://repo.graywolf336.com/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>repo-snapshot</id>
|
||||
<name>repo.graywolf336.com Snapshots</name>
|
||||
<url>http://repo.graywolf336.com/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
@ -1,83 +1,83 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.6.3
|
||||
* @version 1.0.2
|
||||
*/
|
||||
public class HandCuffManager {
|
||||
private HashMap<UUID, Long> handcuffed;
|
||||
private HashMap<UUID, Location> locs;
|
||||
|
||||
/** Constructs a new HandCuff Manager, for handling all the handcuffing. */
|
||||
public HandCuffManager() {
|
||||
this.handcuffed = new HashMap<UUID, Long>();
|
||||
this.locs = new HashMap<UUID, Location>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds handcuffs to a player.
|
||||
*
|
||||
* @param uuid of the player
|
||||
* @param location where the player was handcuffed, so they can't move
|
||||
*/
|
||||
public void addHandCuffs(UUID uuid, Location location) {
|
||||
this.handcuffed.put(uuid, System.currentTimeMillis());
|
||||
this.locs.put(uuid, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the handcuffs from the given player.
|
||||
*
|
||||
* @param uuid of the person to remove the handcuffs from
|
||||
*/
|
||||
public void removeHandCuffs(UUID uuid) {
|
||||
this.handcuffed.remove(uuid);
|
||||
this.locs.remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the player is handcuffed or not.
|
||||
*
|
||||
* @param uuid of the player to check
|
||||
* @return true if they are handcuffed, false if not
|
||||
*/
|
||||
public boolean isHandCuffed(UUID uuid) {
|
||||
return this.handcuffed.containsKey(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next Long time we should send a message to the player.
|
||||
*
|
||||
* @param uuid of the player to get the name we're supposed to message them next
|
||||
* @return long value of the system time in milliseconds
|
||||
*/
|
||||
public Long getNextMessageTime(UUID uuid) {
|
||||
return this.handcuffed.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the time to the next 10 seconds from now to when we should send them a message.
|
||||
*
|
||||
* @param uuid of the player we're setting the message time to
|
||||
*/
|
||||
public void updateNextTime(UUID uuid) {
|
||||
this.handcuffed.put(uuid, System.currentTimeMillis() + 10000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location where the given player was handcuffed at.
|
||||
*
|
||||
* @param uuid of the player get the location for
|
||||
* @return the location where the player was handcuffed at
|
||||
*/
|
||||
public Location getLocation(UUID uuid) {
|
||||
return this.locs.get(uuid);
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.6.3
|
||||
* @version 1.0.2
|
||||
*/
|
||||
public class HandCuffManager {
|
||||
private HashMap<UUID, Long> handcuffed;
|
||||
private HashMap<UUID, Location> locs;
|
||||
|
||||
/** Constructs a new HandCuff Manager, for handling all the handcuffing. */
|
||||
public HandCuffManager() {
|
||||
this.handcuffed = new HashMap<UUID, Long>();
|
||||
this.locs = new HashMap<UUID, Location>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds handcuffs to a player.
|
||||
*
|
||||
* @param uuid of the player
|
||||
* @param location where the player was handcuffed, so they can't move
|
||||
*/
|
||||
public void addHandCuffs(UUID uuid, Location location) {
|
||||
this.handcuffed.put(uuid, System.currentTimeMillis());
|
||||
this.locs.put(uuid, location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the handcuffs from the given player.
|
||||
*
|
||||
* @param uuid of the person to remove the handcuffs from
|
||||
*/
|
||||
public void removeHandCuffs(UUID uuid) {
|
||||
this.handcuffed.remove(uuid);
|
||||
this.locs.remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the player is handcuffed or not.
|
||||
*
|
||||
* @param uuid of the player to check
|
||||
* @return true if they are handcuffed, false if not
|
||||
*/
|
||||
public boolean isHandCuffed(UUID uuid) {
|
||||
return this.handcuffed.containsKey(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next Long time we should send a message to the player.
|
||||
*
|
||||
* @param uuid of the player to get the name we're supposed to message them next
|
||||
* @return long value of the system time in milliseconds
|
||||
*/
|
||||
public Long getNextMessageTime(UUID uuid) {
|
||||
return this.handcuffed.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the time to the next 10 seconds from now to when we should send them a message.
|
||||
*
|
||||
* @param uuid of the player we're setting the message time to
|
||||
*/
|
||||
public void updateNextTime(UUID uuid) {
|
||||
this.handcuffed.put(uuid, System.currentTimeMillis() + 10000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location where the given player was handcuffed at.
|
||||
*
|
||||
* @param uuid of the player get the location for
|
||||
* @return the location where the player was handcuffed at
|
||||
*/
|
||||
public Location getLocation(UUID uuid) {
|
||||
return this.locs.get(uuid);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,271 +1,271 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.CommandHandler;
|
||||
import com.graywolf336.jail.command.JailHandler;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.legacy.LegacyManager;
|
||||
import com.graywolf336.jail.listeners.BlockListener;
|
||||
import com.graywolf336.jail.listeners.CacheListener;
|
||||
import com.graywolf336.jail.listeners.EntityListener;
|
||||
import com.graywolf336.jail.listeners.HandCuffListener;
|
||||
import com.graywolf336.jail.listeners.JailingListener;
|
||||
import com.graywolf336.jail.listeners.MoveProtectionListener;
|
||||
import com.graywolf336.jail.listeners.PlayerListener;
|
||||
import com.graywolf336.jail.listeners.ProtectionListener;
|
||||
|
||||
/**
|
||||
* The main class for this Jail plugin, holds instances of vital classes.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 1.x.x
|
||||
* @version 3.0.0
|
||||
*/
|
||||
public class JailMain extends JavaPlugin {
|
||||
private CommandHandler cmdHand;
|
||||
private HandCuffManager hcm;
|
||||
private JailHandler jh;
|
||||
private JailIO io;
|
||||
private JailManager jm;
|
||||
private JailPayManager jpm;
|
||||
private JailStickManager jsm;
|
||||
private JailTimer jt;
|
||||
private PrisonerManager pm;
|
||||
private ScoreBoardManager sbm;
|
||||
private MoveProtectionListener mpl;
|
||||
private boolean debug = false;
|
||||
|
||||
public void onEnable() {
|
||||
loadConfig();
|
||||
|
||||
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
||||
if(debug) getLogger().info("Debugging enabled.");
|
||||
|
||||
hcm = new HandCuffManager();
|
||||
jm = new JailManager(this);
|
||||
|
||||
//Try to load the old stuff before we load anything, esp the storage stuff
|
||||
LegacyManager lm = new LegacyManager(this);
|
||||
if(lm.doWeNeedToConvert()) {
|
||||
lm.convertOldData();
|
||||
if(!lm.wasAnythingConverted()) getLogger().severe("We was unable to convert some, or all, of the old data.");
|
||||
}
|
||||
|
||||
io = new JailIO(this);
|
||||
io.loadLanguage();
|
||||
|
||||
//If the prepareStorage returns false, we need to disable the plugin
|
||||
if(!io.prepareStorage(true)) {
|
||||
this.getLogger().severe("An error occured while preparing the connection to the storage, please see the error above for more information.");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
io.loadJails();
|
||||
|
||||
//If we converted something, let's save EVERYTHING including the cells
|
||||
if(lm.wasAnythingConverted()) {
|
||||
io.saveEverything();
|
||||
}
|
||||
|
||||
cmdHand = new CommandHandler(this);
|
||||
jh = new JailHandler(this);
|
||||
pm = new PrisonerManager(this);
|
||||
jsm = new JailStickManager(this);
|
||||
|
||||
PluginManager plm = this.getServer().getPluginManager();
|
||||
plm.registerEvents(new BlockListener(this), this);
|
||||
plm.registerEvents(new CacheListener(this), this);
|
||||
plm.registerEvents(new EntityListener(this), this);
|
||||
plm.registerEvents(new HandCuffListener(this), this);
|
||||
plm.registerEvents(new JailingListener(this), this);
|
||||
plm.registerEvents(new PlayerListener(this), this);
|
||||
plm.registerEvents(new ProtectionListener(this), this);
|
||||
|
||||
//Only register the move protection listener if this is enabled in the
|
||||
//config when we first start the plugin. The reason for this change is
|
||||
//that the move event is called a ton of times per single move and so
|
||||
//not registering this event listener will hopefully safe some performance.
|
||||
//But doing this also forces people to restart their server if they to
|
||||
//enable it after disabling it.
|
||||
if(getConfig().getBoolean(Settings.MOVEPROTECTION.getPath())) {
|
||||
this.mpl = new MoveProtectionListener(this);
|
||||
plm.registerEvents(this.mpl, this);
|
||||
}
|
||||
|
||||
jt = new JailTimer(this);
|
||||
|
||||
reloadJailPayManager();
|
||||
|
||||
sbm = new ScoreBoardManager(this);
|
||||
|
||||
getLogger().info("Completed enablement.");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
if(jm != null)
|
||||
for(Jail j : jm.getJails())
|
||||
io.saveJail(j);
|
||||
|
||||
if(jt != null)
|
||||
if(jt.getTimer() != null)
|
||||
jt.getTimer().stop();
|
||||
|
||||
if(io != null)
|
||||
io.closeConnection();
|
||||
|
||||
jt = null;
|
||||
sbm = null;
|
||||
jpm = null;
|
||||
cmdHand = null;
|
||||
pm = null;
|
||||
jm = null;
|
||||
jsm = null;
|
||||
io = null;
|
||||
hcm = null;
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
//Only create the default config if it doesn't exist
|
||||
saveDefaultConfig();
|
||||
|
||||
//Append new key-value pairs to the config
|
||||
getConfig().options().copyDefaults(true);
|
||||
|
||||
// Set the header and save
|
||||
getConfig().options().header(getHeader());
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private String getHeader() {
|
||||
String sep = System.getProperty("line.separator");
|
||||
|
||||
return "###################" + sep
|
||||
+ "Jail v" + this.getDescription().getVersion() + " config file" + sep
|
||||
+ "Note: You -must- use spaces instead of tabs!" + sep +
|
||||
"###################";
|
||||
}
|
||||
|
||||
/* Majority of the new command system was heavily influenced by the MobArena.
|
||||
* Thank you garbagemule for the great system you have in place there.
|
||||
*
|
||||
* Send the command off to the CommandHandler class, that way this main class doesn't get clogged up.
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
|
||||
jh.parseCommand(jm, sender, args);
|
||||
}else {
|
||||
cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
|
||||
}
|
||||
|
||||
return true;//Always return true here, that way we can handle the help and command usage ourself.
|
||||
}
|
||||
|
||||
/** Reloads the scoreboard manager class, useful when something is changed int he config about it. */
|
||||
public void reloadScoreBoardManager() {
|
||||
this.sbm.removeAllScoreboards();
|
||||
this.sbm = null;
|
||||
this.sbm = new ScoreBoardManager(this);
|
||||
|
||||
if(getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
for(Jail j : jm.getJails()) {
|
||||
for(Prisoner p : j.getAllPrisoners().values()) {
|
||||
if(getServer().getPlayer(p.getUUID()) != null) {
|
||||
this.sbm.addScoreBoard(getServer().getPlayer(p.getUUID()), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Reloads the Jail Sticks, so the new ones can be loaded from the config. */
|
||||
public void reloadJailSticks() {
|
||||
this.jsm.removeAllStickUsers();
|
||||
this.jsm = null;
|
||||
this.jsm = new JailStickManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the {@link JailPayManager}.
|
||||
*
|
||||
* @throws Exception If we couldn't successfully create a new Jail Pay Manager instance.
|
||||
*/
|
||||
public void reloadJailPayManager() {
|
||||
this.jpm = null;
|
||||
|
||||
if(getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
||||
if(getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
this.jpm = new JailPayManager(this);
|
||||
}else {
|
||||
getConfig().set(Settings.JAILPAYENABLED.getPath(), false);
|
||||
getLogger().severe("Jail Pay couldn't find an economy, disabling Jail Pay.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the {@link HandCuffManager} instance. */
|
||||
public HandCuffManager getHandCuffManager() {
|
||||
return this.hcm;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailIO} instance. */
|
||||
public JailIO getJailIO() {
|
||||
return this.io;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailManager} instance. */
|
||||
public JailManager getJailManager() {
|
||||
return this.jm;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailPayManager} instance. */
|
||||
public JailPayManager getJailPayManager() {
|
||||
return this.jpm;
|
||||
}
|
||||
|
||||
/** Gets the {@link PrisonerManager} instance. */
|
||||
public PrisonerManager getPrisonerManager() {
|
||||
return this.pm;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailStickManager} instance. */
|
||||
public JailStickManager getJailStickManager() {
|
||||
return this.jsm;
|
||||
}
|
||||
|
||||
/** Gets the {@link ScoreBoardManager} instance. */
|
||||
public ScoreBoardManager getScoreBoardManager() {
|
||||
return this.sbm;
|
||||
}
|
||||
|
||||
/** Sets whether the plugin is in debugging or not. */
|
||||
public boolean setDebugging(boolean debug) {
|
||||
this.debug = debug;
|
||||
|
||||
//Save whether we are debugging when we disable the plugin
|
||||
getConfig().set(Settings.DEBUG.getPath(), this.debug);
|
||||
saveConfig();
|
||||
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
/** Returns if the plugin is in debug state or not. */
|
||||
public boolean inDebug() {
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
/** Logs a debugging message to the console if debugging is enabled. */
|
||||
public void debug(String message) {
|
||||
if(inDebug()) getLogger().info("[Debug]: " + message);
|
||||
}
|
||||
|
||||
public MoveProtectionListener getPlayerMoveListener() {
|
||||
return this.mpl;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.CommandHandler;
|
||||
import com.graywolf336.jail.command.JailHandler;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.legacy.LegacyManager;
|
||||
import com.graywolf336.jail.listeners.BlockListener;
|
||||
import com.graywolf336.jail.listeners.CacheListener;
|
||||
import com.graywolf336.jail.listeners.EntityListener;
|
||||
import com.graywolf336.jail.listeners.HandCuffListener;
|
||||
import com.graywolf336.jail.listeners.JailingListener;
|
||||
import com.graywolf336.jail.listeners.MoveProtectionListener;
|
||||
import com.graywolf336.jail.listeners.PlayerListener;
|
||||
import com.graywolf336.jail.listeners.ProtectionListener;
|
||||
|
||||
/**
|
||||
* The main class for this Jail plugin, holds instances of vital classes.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 1.x.x
|
||||
* @version 3.0.0
|
||||
*/
|
||||
public class JailMain extends JavaPlugin {
|
||||
private CommandHandler cmdHand;
|
||||
private HandCuffManager hcm;
|
||||
private JailHandler jh;
|
||||
private JailIO io;
|
||||
private JailManager jm;
|
||||
private JailPayManager jpm;
|
||||
private JailStickManager jsm;
|
||||
private JailTimer jt;
|
||||
private PrisonerManager pm;
|
||||
private ScoreBoardManager sbm;
|
||||
private MoveProtectionListener mpl;
|
||||
private boolean debug = false;
|
||||
|
||||
public void onEnable() {
|
||||
loadConfig();
|
||||
|
||||
debug = getConfig().getBoolean(Settings.DEBUG.getPath());
|
||||
if(debug) getLogger().info("Debugging enabled.");
|
||||
|
||||
hcm = new HandCuffManager();
|
||||
jm = new JailManager(this);
|
||||
|
||||
//Try to load the old stuff before we load anything, esp the storage stuff
|
||||
LegacyManager lm = new LegacyManager(this);
|
||||
if(lm.doWeNeedToConvert()) {
|
||||
lm.convertOldData();
|
||||
if(!lm.wasAnythingConverted()) getLogger().severe("We was unable to convert some, or all, of the old data.");
|
||||
}
|
||||
|
||||
io = new JailIO(this);
|
||||
io.loadLanguage();
|
||||
|
||||
//If the prepareStorage returns false, we need to disable the plugin
|
||||
if(!io.prepareStorage(true)) {
|
||||
this.getLogger().severe("An error occured while preparing the connection to the storage, please see the error above for more information.");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
io.loadJails();
|
||||
|
||||
//If we converted something, let's save EVERYTHING including the cells
|
||||
if(lm.wasAnythingConverted()) {
|
||||
io.saveEverything();
|
||||
}
|
||||
|
||||
cmdHand = new CommandHandler(this);
|
||||
jh = new JailHandler(this);
|
||||
pm = new PrisonerManager(this);
|
||||
jsm = new JailStickManager(this);
|
||||
|
||||
PluginManager plm = this.getServer().getPluginManager();
|
||||
plm.registerEvents(new BlockListener(this), this);
|
||||
plm.registerEvents(new CacheListener(this), this);
|
||||
plm.registerEvents(new EntityListener(this), this);
|
||||
plm.registerEvents(new HandCuffListener(this), this);
|
||||
plm.registerEvents(new JailingListener(this), this);
|
||||
plm.registerEvents(new PlayerListener(this), this);
|
||||
plm.registerEvents(new ProtectionListener(this), this);
|
||||
|
||||
//Only register the move protection listener if this is enabled in the
|
||||
//config when we first start the plugin. The reason for this change is
|
||||
//that the move event is called a ton of times per single move and so
|
||||
//not registering this event listener will hopefully safe some performance.
|
||||
//But doing this also forces people to restart their server if they to
|
||||
//enable it after disabling it.
|
||||
if(getConfig().getBoolean(Settings.MOVEPROTECTION.getPath())) {
|
||||
this.mpl = new MoveProtectionListener(this);
|
||||
plm.registerEvents(this.mpl, this);
|
||||
}
|
||||
|
||||
jt = new JailTimer(this);
|
||||
|
||||
reloadJailPayManager();
|
||||
|
||||
sbm = new ScoreBoardManager(this);
|
||||
|
||||
getLogger().info("Completed enablement.");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
if(jm != null)
|
||||
for(Jail j : jm.getJails())
|
||||
io.saveJail(j);
|
||||
|
||||
if(jt != null)
|
||||
if(jt.getTimer() != null)
|
||||
jt.getTimer().stop();
|
||||
|
||||
if(io != null)
|
||||
io.closeConnection();
|
||||
|
||||
jt = null;
|
||||
sbm = null;
|
||||
jpm = null;
|
||||
cmdHand = null;
|
||||
pm = null;
|
||||
jm = null;
|
||||
jsm = null;
|
||||
io = null;
|
||||
hcm = null;
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
//Only create the default config if it doesn't exist
|
||||
saveDefaultConfig();
|
||||
|
||||
//Append new key-value pairs to the config
|
||||
getConfig().options().copyDefaults(true);
|
||||
|
||||
// Set the header and save
|
||||
getConfig().options().header(getHeader());
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
private String getHeader() {
|
||||
String sep = System.getProperty("line.separator");
|
||||
|
||||
return "###################" + sep
|
||||
+ "Jail v" + this.getDescription().getVersion() + " config file" + sep
|
||||
+ "Note: You -must- use spaces instead of tabs!" + sep +
|
||||
"###################";
|
||||
}
|
||||
|
||||
/* Majority of the new command system was heavily influenced by the MobArena.
|
||||
* Thank you garbagemule for the great system you have in place there.
|
||||
*
|
||||
* Send the command off to the CommandHandler class, that way this main class doesn't get clogged up.
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
|
||||
if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
|
||||
jh.parseCommand(jm, sender, args);
|
||||
}else {
|
||||
cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
|
||||
}
|
||||
|
||||
return true;//Always return true here, that way we can handle the help and command usage ourself.
|
||||
}
|
||||
|
||||
/** Reloads the scoreboard manager class, useful when something is changed int he config about it. */
|
||||
public void reloadScoreBoardManager() {
|
||||
this.sbm.removeAllScoreboards();
|
||||
this.sbm = null;
|
||||
this.sbm = new ScoreBoardManager(this);
|
||||
|
||||
if(getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
for(Jail j : jm.getJails()) {
|
||||
for(Prisoner p : j.getAllPrisoners().values()) {
|
||||
if(getServer().getPlayer(p.getUUID()) != null) {
|
||||
this.sbm.addScoreBoard(getServer().getPlayer(p.getUUID()), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Reloads the Jail Sticks, so the new ones can be loaded from the config. */
|
||||
public void reloadJailSticks() {
|
||||
this.jsm.removeAllStickUsers();
|
||||
this.jsm = null;
|
||||
this.jsm = new JailStickManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the {@link JailPayManager}.
|
||||
*
|
||||
* @throws Exception If we couldn't successfully create a new Jail Pay Manager instance.
|
||||
*/
|
||||
public void reloadJailPayManager() {
|
||||
this.jpm = null;
|
||||
|
||||
if(getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
||||
if(getServer().getPluginManager().isPluginEnabled("Vault")) {
|
||||
this.jpm = new JailPayManager(this);
|
||||
}else {
|
||||
getConfig().set(Settings.JAILPAYENABLED.getPath(), false);
|
||||
getLogger().severe("Jail Pay couldn't find an economy, disabling Jail Pay.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the {@link HandCuffManager} instance. */
|
||||
public HandCuffManager getHandCuffManager() {
|
||||
return this.hcm;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailIO} instance. */
|
||||
public JailIO getJailIO() {
|
||||
return this.io;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailManager} instance. */
|
||||
public JailManager getJailManager() {
|
||||
return this.jm;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailPayManager} instance. */
|
||||
public JailPayManager getJailPayManager() {
|
||||
return this.jpm;
|
||||
}
|
||||
|
||||
/** Gets the {@link PrisonerManager} instance. */
|
||||
public PrisonerManager getPrisonerManager() {
|
||||
return this.pm;
|
||||
}
|
||||
|
||||
/** Gets the {@link JailStickManager} instance. */
|
||||
public JailStickManager getJailStickManager() {
|
||||
return this.jsm;
|
||||
}
|
||||
|
||||
/** Gets the {@link ScoreBoardManager} instance. */
|
||||
public ScoreBoardManager getScoreBoardManager() {
|
||||
return this.sbm;
|
||||
}
|
||||
|
||||
/** Sets whether the plugin is in debugging or not. */
|
||||
public boolean setDebugging(boolean debug) {
|
||||
this.debug = debug;
|
||||
|
||||
//Save whether we are debugging when we disable the plugin
|
||||
getConfig().set(Settings.DEBUG.getPath(), this.debug);
|
||||
saveConfig();
|
||||
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
/** Returns if the plugin is in debug state or not. */
|
||||
public boolean inDebug() {
|
||||
return this.debug;
|
||||
}
|
||||
|
||||
/** Logs a debugging message to the console if debugging is enabled. */
|
||||
public void debug(String message) {
|
||||
if(inDebug()) getLogger().info("[Debug]: " + message);
|
||||
}
|
||||
|
||||
public MoveProtectionListener getPlayerMoveListener() {
|
||||
return this.mpl;
|
||||
}
|
||||
}
|
||||
|
@ -1,172 +1,172 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class JailPayManager {
|
||||
private Economy economy = null;
|
||||
private double minteCost, infiniteCost;
|
||||
private Material item;
|
||||
private boolean infinite, timed;
|
||||
|
||||
public JailPayManager(JailMain plugin) {
|
||||
this.item = Material.getMaterial(plugin.getConfig().getString(Settings.JAILPAYITEM.getPath().toUpperCase()));
|
||||
if(this.item == null) this.item = Material.AIR;
|
||||
|
||||
this.minteCost = plugin.getConfig().getDouble(Settings.JAILPAYPRICEPERMINUTE.getPath());
|
||||
|
||||
if(!this.usingItemsForPayment()) {
|
||||
if(!this.setupEconomy(plugin)) {
|
||||
plugin.getConfig().set(Settings.JAILPAYENABLED.getPath(), false);
|
||||
}
|
||||
}
|
||||
|
||||
this.timed = plugin.getConfig().getDouble(Settings.JAILPAYPRICEPERMINUTE.getPath()) != 0;
|
||||
this.infinite = plugin.getConfig().getDouble(Settings.JAILPAYPRICEINFINITE.getPath()) != 0;
|
||||
}
|
||||
|
||||
/** Checks if paying for infinite is enabled. */
|
||||
public boolean isInfiniteEnabled() {
|
||||
return this.infinite;
|
||||
}
|
||||
|
||||
/** Checks if paying for timed is enabled. */
|
||||
public boolean isTimedEnabled() {
|
||||
return this.timed;
|
||||
}
|
||||
|
||||
/** Gets how much it cost per minute in string format. */
|
||||
public String getCostPerMinute() {
|
||||
return String.valueOf(this.minteCost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates how much players have to pay to get completely free.
|
||||
*
|
||||
* @param prisoner data of who we're calculating
|
||||
* @return The economy cost the prisoner will need to pay to get completely free.
|
||||
*/
|
||||
public double calculateBill(Prisoner prisoner) {
|
||||
return prisoner.getRemainingTime() > 0 ? prisoner.getRemainingTimeInMinutes() * this.minteCost : infiniteCost;
|
||||
}
|
||||
|
||||
/** Gets how many minutes someone is paying for (rounds to the lowest number). */
|
||||
public long getMinutesPayingFor(double amount) {
|
||||
return (long) Math.floor(amount / this.minteCost);
|
||||
}
|
||||
|
||||
/** Returns if we are using items for payment instead of economy. */
|
||||
public boolean usingItemsForPayment() {
|
||||
return this.item != Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Material} it costs for jail pay, will be air if using economy.
|
||||
*
|
||||
* @return The item type it costs, air if using virtual economy.
|
||||
*/
|
||||
public Material getItemItCost() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has enough money/items to pay what they have said they want to.
|
||||
*
|
||||
* @param p The player who is doing the paying.
|
||||
* @param amt The amount to check they if they have.
|
||||
* @return true if they have enough, false if not.
|
||||
*/
|
||||
public boolean hasEnoughToPay(Player p, double amt) {
|
||||
if(this.usingItemsForPayment()) {
|
||||
return p.getInventory().contains(this.item, (int) Math.ceil(amt));
|
||||
}else {
|
||||
|
||||
return this.economy.has(p.getName(), amt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pays the required fees from the given player, removing items or money from economy.
|
||||
*
|
||||
* @param p The player who is paying.
|
||||
* @param amt The amount of items or money to withdraw from the player.
|
||||
*/
|
||||
public void pay(Player p, double amt) {
|
||||
if(this.usingItemsForPayment()) {
|
||||
int amtNeeded = (int) Math.ceil(amt);
|
||||
|
||||
for (int i = 0; i < p.getInventory().getSize(); i++) {
|
||||
ItemStack it = p.getInventory().getItem(i);
|
||||
|
||||
//The item is either air or we doesn't match out needs
|
||||
if(it == null || it.getType() != this.item) continue;
|
||||
|
||||
//If the itemstack has more than or equal to the amount
|
||||
//that we need, remove it and subject from the amt needed
|
||||
if (amtNeeded >= it.getAmount()) {
|
||||
amtNeeded -= it.getAmount();
|
||||
p.getInventory().clear(i);
|
||||
} else {
|
||||
//Otherwise, subject from the itemstack just the amount we need
|
||||
it.setAmount(it.getAmount() - amtNeeded);
|
||||
p.getInventory().setItem(i, it);
|
||||
amtNeeded = 0;
|
||||
}
|
||||
|
||||
if (amtNeeded == 0) break;
|
||||
}
|
||||
}else {
|
||||
this.economy.withdrawPlayer(p.getName(), amt);
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the name of the item in nice capitals. */
|
||||
public String getCurrencyName(){
|
||||
if(this.usingItemsForPayment()) {
|
||||
String name = item.toString().replaceAll("_", " ");
|
||||
|
||||
if(name.contains(" ")){
|
||||
String[] split = name.split(" ");
|
||||
for(int i=0; i < split.length; i++){
|
||||
split[i] = split[i].substring(0, 1).toUpperCase() + split[i].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
name = "";
|
||||
for(String s : split){
|
||||
name += " " + s;
|
||||
}
|
||||
|
||||
name = name.substring(1);
|
||||
} else {
|
||||
name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return name;
|
||||
}else {
|
||||
return this.economy.currencyNamePlural();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the economy provider to do transaction with. */
|
||||
public Economy getEconomy() {
|
||||
return this.economy;
|
||||
}
|
||||
|
||||
private boolean setupEconomy(JailMain plugin) {
|
||||
if (economy != null) return true;
|
||||
|
||||
RegisteredServiceProvider<Economy> economyProvider = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
|
||||
return (economy != null);
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class JailPayManager {
|
||||
private Economy economy = null;
|
||||
private double minteCost, infiniteCost;
|
||||
private Material item;
|
||||
private boolean infinite, timed;
|
||||
|
||||
public JailPayManager(JailMain plugin) {
|
||||
this.item = Material.getMaterial(plugin.getConfig().getString(Settings.JAILPAYITEM.getPath().toUpperCase()));
|
||||
if(this.item == null) this.item = Material.AIR;
|
||||
|
||||
this.minteCost = plugin.getConfig().getDouble(Settings.JAILPAYPRICEPERMINUTE.getPath());
|
||||
|
||||
if(!this.usingItemsForPayment()) {
|
||||
if(!this.setupEconomy(plugin)) {
|
||||
plugin.getConfig().set(Settings.JAILPAYENABLED.getPath(), false);
|
||||
}
|
||||
}
|
||||
|
||||
this.timed = plugin.getConfig().getDouble(Settings.JAILPAYPRICEPERMINUTE.getPath()) != 0;
|
||||
this.infinite = plugin.getConfig().getDouble(Settings.JAILPAYPRICEINFINITE.getPath()) != 0;
|
||||
}
|
||||
|
||||
/** Checks if paying for infinite is enabled. */
|
||||
public boolean isInfiniteEnabled() {
|
||||
return this.infinite;
|
||||
}
|
||||
|
||||
/** Checks if paying for timed is enabled. */
|
||||
public boolean isTimedEnabled() {
|
||||
return this.timed;
|
||||
}
|
||||
|
||||
/** Gets how much it cost per minute in string format. */
|
||||
public String getCostPerMinute() {
|
||||
return String.valueOf(this.minteCost);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates how much players have to pay to get completely free.
|
||||
*
|
||||
* @param prisoner data of who we're calculating
|
||||
* @return The economy cost the prisoner will need to pay to get completely free.
|
||||
*/
|
||||
public double calculateBill(Prisoner prisoner) {
|
||||
return prisoner.getRemainingTime() > 0 ? prisoner.getRemainingTimeInMinutes() * this.minteCost : infiniteCost;
|
||||
}
|
||||
|
||||
/** Gets how many minutes someone is paying for (rounds to the lowest number). */
|
||||
public long getMinutesPayingFor(double amount) {
|
||||
return (long) Math.floor(amount / this.minteCost);
|
||||
}
|
||||
|
||||
/** Returns if we are using items for payment instead of economy. */
|
||||
public boolean usingItemsForPayment() {
|
||||
return this.item != Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Material} it costs for jail pay, will be air if using economy.
|
||||
*
|
||||
* @return The item type it costs, air if using virtual economy.
|
||||
*/
|
||||
public Material getItemItCost() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has enough money/items to pay what they have said they want to.
|
||||
*
|
||||
* @param p The player who is doing the paying.
|
||||
* @param amt The amount to check they if they have.
|
||||
* @return true if they have enough, false if not.
|
||||
*/
|
||||
public boolean hasEnoughToPay(Player p, double amt) {
|
||||
if(this.usingItemsForPayment()) {
|
||||
return p.getInventory().contains(this.item, (int) Math.ceil(amt));
|
||||
}else {
|
||||
|
||||
return this.economy.has(p.getName(), amt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pays the required fees from the given player, removing items or money from economy.
|
||||
*
|
||||
* @param p The player who is paying.
|
||||
* @param amt The amount of items or money to withdraw from the player.
|
||||
*/
|
||||
public void pay(Player p, double amt) {
|
||||
if(this.usingItemsForPayment()) {
|
||||
int amtNeeded = (int) Math.ceil(amt);
|
||||
|
||||
for (int i = 0; i < p.getInventory().getSize(); i++) {
|
||||
ItemStack it = p.getInventory().getItem(i);
|
||||
|
||||
//The item is either air or we doesn't match out needs
|
||||
if(it == null || it.getType() != this.item) continue;
|
||||
|
||||
//If the itemstack has more than or equal to the amount
|
||||
//that we need, remove it and subject from the amt needed
|
||||
if (amtNeeded >= it.getAmount()) {
|
||||
amtNeeded -= it.getAmount();
|
||||
p.getInventory().clear(i);
|
||||
} else {
|
||||
//Otherwise, subject from the itemstack just the amount we need
|
||||
it.setAmount(it.getAmount() - amtNeeded);
|
||||
p.getInventory().setItem(i, it);
|
||||
amtNeeded = 0;
|
||||
}
|
||||
|
||||
if (amtNeeded == 0) break;
|
||||
}
|
||||
}else {
|
||||
this.economy.withdrawPlayer(p.getName(), amt);
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the name of the item in nice capitals. */
|
||||
public String getCurrencyName(){
|
||||
if(this.usingItemsForPayment()) {
|
||||
String name = item.toString().replaceAll("_", " ");
|
||||
|
||||
if(name.contains(" ")){
|
||||
String[] split = name.split(" ");
|
||||
for(int i=0; i < split.length; i++){
|
||||
split[i] = split[i].substring(0, 1).toUpperCase() + split[i].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
name = "";
|
||||
for(String s : split){
|
||||
name += " " + s;
|
||||
}
|
||||
|
||||
name = name.substring(1);
|
||||
} else {
|
||||
name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return name;
|
||||
}else {
|
||||
return this.economy.currencyNamePlural();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the economy provider to do transaction with. */
|
||||
public Economy getEconomy() {
|
||||
return this.economy;
|
||||
}
|
||||
|
||||
private boolean setupEconomy(JailMain plugin) {
|
||||
if (economy != null) return true;
|
||||
|
||||
RegisteredServiceProvider<Economy> economyProvider = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
economy = economyProvider.getProvider();
|
||||
}
|
||||
|
||||
return (economy != null);
|
||||
}
|
||||
}
|
||||
|
@ -1,173 +1,173 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.beans.Stick;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
/**
|
||||
* Manages the jail stick users.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 1.0.2
|
||||
* @since 3.0.0
|
||||
*
|
||||
*/
|
||||
public class JailStickManager {
|
||||
private ArrayList<String> stickers;
|
||||
private HashMap<Material, Stick> sticks;
|
||||
|
||||
public JailStickManager(JailMain plugin) {
|
||||
this.stickers = new ArrayList<String>();
|
||||
this.sticks = new HashMap<Material, Stick>();
|
||||
|
||||
this.loadJailSticks(plugin);
|
||||
}
|
||||
|
||||
private void loadJailSticks(JailMain pl) {
|
||||
FileConfiguration config = pl.getConfig();
|
||||
|
||||
//item name,time,jail name,reason
|
||||
for(String s : config.getStringList(Settings.JAILSTICKSTICKS.getPath())) {
|
||||
pl.debug(s);
|
||||
String[] a = s.split(",");
|
||||
|
||||
//Check if the jail given, if any, exists
|
||||
if(!a[2].isEmpty()) {
|
||||
if(!pl.getJailManager().isValidJail(a[2])) {
|
||||
pl.getLogger().severe(s);
|
||||
pl.getLogger().severe("The above jail stick configuration is invalid and references a jail that doesn't exist.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Material m = Material.getMaterial(a[0].toUpperCase());
|
||||
if(this.sticks.containsKey(m)) {
|
||||
pl.getLogger().severe(s);
|
||||
pl.getLogger().severe("You can not use the same item for two different Jail Sticks. This already exists as a Jail Stick: " + a[0]);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
this.sticks.put(m, new Stick(a[2], a[3], Long.valueOf(a[1])));
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe(s);
|
||||
pl.getLogger().severe("Unable to create a new stick for " + a[0] + ", see the exception above for details.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int c = sticks.size();
|
||||
pl.getLogger().info("Loaded " + c + " jail stick" + (c == 1 ? "" : "s") + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Stick jail stick} by the provided {@link Material}, can be null.
|
||||
*
|
||||
* @param mat of the stick to get
|
||||
* @return The {@link Stick jail stick}
|
||||
*/
|
||||
public Stick getStick(Material mat) {
|
||||
return this.sticks.get(mat);
|
||||
}
|
||||
|
||||
/** Checks if the provided Material is a valid {@link Stick jail stick}. */
|
||||
public boolean isValidStick(Material mat) {
|
||||
return this.sticks.containsKey(mat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to be using a jail stick, with the player instance.
|
||||
*
|
||||
* @param player to add
|
||||
*/
|
||||
public void addUsingStick(Player player) {
|
||||
this.stickers.add(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to be using a jail stick, with their username.
|
||||
*
|
||||
* @param name of the player to add
|
||||
*/
|
||||
public void addUsingStick(String name) {
|
||||
this.stickers.add(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from using a jail stick, with the player instance.
|
||||
*
|
||||
* @param player to remove using a jail stick
|
||||
*/
|
||||
public void removeUsingStick(Player player) {
|
||||
this.stickers.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from using a jail stick, with their username.
|
||||
*
|
||||
* @param name of the player to remove using a jail stick
|
||||
*/
|
||||
public void removeUsingStick(String name) {
|
||||
this.stickers.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the player is using a jail stick.
|
||||
*
|
||||
* @param player to check if using one
|
||||
* @return true if the player is using a jail stick, false if not
|
||||
*/
|
||||
public boolean isUsingJailStick(Player player) {
|
||||
return this.stickers.contains(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the player is using a jail stick.
|
||||
*
|
||||
* @param name of the player to check if using one
|
||||
* @return true if the player is using a jail stick, false if not
|
||||
*/
|
||||
public boolean isUsingJailStick(String name) {
|
||||
return this.stickers.contains(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
|
||||
*
|
||||
* @param player to toggle using a stick
|
||||
* @return true if we enabled it, false if we disabled it.
|
||||
*/
|
||||
public boolean toggleUsingStick(Player player) {
|
||||
return this.toggleUsingStick(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
|
||||
*
|
||||
* @param name of the person to toggle
|
||||
* @return true if we enabled it, false if we disabled it.
|
||||
*/
|
||||
public boolean toggleUsingStick(String name) {
|
||||
if(this.stickers.contains(name)) {
|
||||
this.stickers.remove(name);
|
||||
return false;
|
||||
}else {
|
||||
this.stickers.add(name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Removes all the users currently using the sticks. */
|
||||
public void removeAllStickUsers() {
|
||||
for(String s: stickers) {
|
||||
this.removeUsingStick(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.beans.Stick;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
/**
|
||||
* Manages the jail stick users.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 1.0.2
|
||||
* @since 3.0.0
|
||||
*
|
||||
*/
|
||||
public class JailStickManager {
|
||||
private ArrayList<String> stickers;
|
||||
private HashMap<Material, Stick> sticks;
|
||||
|
||||
public JailStickManager(JailMain plugin) {
|
||||
this.stickers = new ArrayList<String>();
|
||||
this.sticks = new HashMap<Material, Stick>();
|
||||
|
||||
this.loadJailSticks(plugin);
|
||||
}
|
||||
|
||||
private void loadJailSticks(JailMain pl) {
|
||||
FileConfiguration config = pl.getConfig();
|
||||
|
||||
//item name,time,jail name,reason
|
||||
for(String s : config.getStringList(Settings.JAILSTICKSTICKS.getPath())) {
|
||||
pl.debug(s);
|
||||
String[] a = s.split(",");
|
||||
|
||||
//Check if the jail given, if any, exists
|
||||
if(!a[2].isEmpty()) {
|
||||
if(!pl.getJailManager().isValidJail(a[2])) {
|
||||
pl.getLogger().severe(s);
|
||||
pl.getLogger().severe("The above jail stick configuration is invalid and references a jail that doesn't exist.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Material m = Material.getMaterial(a[0].toUpperCase());
|
||||
if(this.sticks.containsKey(m)) {
|
||||
pl.getLogger().severe(s);
|
||||
pl.getLogger().severe("You can not use the same item for two different Jail Sticks. This already exists as a Jail Stick: " + a[0]);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
this.sticks.put(m, new Stick(a[2], a[3], Long.valueOf(a[1])));
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
pl.getLogger().severe(s);
|
||||
pl.getLogger().severe("Unable to create a new stick for " + a[0] + ", see the exception above for details.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int c = sticks.size();
|
||||
pl.getLogger().info("Loaded " + c + " jail stick" + (c == 1 ? "" : "s") + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Stick jail stick} by the provided {@link Material}, can be null.
|
||||
*
|
||||
* @param mat of the stick to get
|
||||
* @return The {@link Stick jail stick}
|
||||
*/
|
||||
public Stick getStick(Material mat) {
|
||||
return this.sticks.get(mat);
|
||||
}
|
||||
|
||||
/** Checks if the provided Material is a valid {@link Stick jail stick}. */
|
||||
public boolean isValidStick(Material mat) {
|
||||
return this.sticks.containsKey(mat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to be using a jail stick, with the player instance.
|
||||
*
|
||||
* @param player to add
|
||||
*/
|
||||
public void addUsingStick(Player player) {
|
||||
this.stickers.add(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to be using a jail stick, with their username.
|
||||
*
|
||||
* @param name of the player to add
|
||||
*/
|
||||
public void addUsingStick(String name) {
|
||||
this.stickers.add(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from using a jail stick, with the player instance.
|
||||
*
|
||||
* @param player to remove using a jail stick
|
||||
*/
|
||||
public void removeUsingStick(Player player) {
|
||||
this.stickers.remove(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from using a jail stick, with their username.
|
||||
*
|
||||
* @param name of the player to remove using a jail stick
|
||||
*/
|
||||
public void removeUsingStick(String name) {
|
||||
this.stickers.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the player is using a jail stick.
|
||||
*
|
||||
* @param player to check if using one
|
||||
* @return true if the player is using a jail stick, false if not
|
||||
*/
|
||||
public boolean isUsingJailStick(Player player) {
|
||||
return this.stickers.contains(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the player is using a jail stick.
|
||||
*
|
||||
* @param name of the player to check if using one
|
||||
* @return true if the player is using a jail stick, false if not
|
||||
*/
|
||||
public boolean isUsingJailStick(String name) {
|
||||
return this.stickers.contains(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
|
||||
*
|
||||
* @param player to toggle using a stick
|
||||
* @return true if we enabled it, false if we disabled it.
|
||||
*/
|
||||
public boolean toggleUsingStick(Player player) {
|
||||
return this.toggleUsingStick(player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles whether the player is using a jail stick, returning the true if enabled false if disabled.
|
||||
*
|
||||
* @param name of the person to toggle
|
||||
* @return true if we enabled it, false if we disabled it.
|
||||
*/
|
||||
public boolean toggleUsingStick(String name) {
|
||||
if(this.stickers.contains(name)) {
|
||||
this.stickers.remove(name);
|
||||
return false;
|
||||
}else {
|
||||
this.stickers.add(name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Removes all the users currently using the sticks. */
|
||||
public void removeAllStickUsers() {
|
||||
for(String s: stickers) {
|
||||
this.removeUsingStick(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,112 +1,112 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
/**
|
||||
* Contains all the logic for counting down the time of the prisoners time.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
* @version 3.0.0
|
||||
*
|
||||
*/
|
||||
public class JailTimer {
|
||||
private JailMain pl;
|
||||
private Timer timer;
|
||||
private Long lastTime;
|
||||
|
||||
public JailTimer(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
if(pl.getConfig().getBoolean(Settings.USEBUKKITTIMER.getPath())) {
|
||||
pl.getLogger().info("Using the Bukkit Scheduler.");
|
||||
pl.getServer().getScheduler().scheduleSyncRepeatingTask(pl, new TimeEvent(), 20, 20);
|
||||
}else {
|
||||
pl.getLogger().info("Using the Java Timer.");
|
||||
timer = new Timer(1000, new ActionListener () {
|
||||
public void actionPerformed (ActionEvent event) {
|
||||
pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new TimeEvent());
|
||||
};
|
||||
});
|
||||
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the instance of this timer. */
|
||||
public Timer getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
|
||||
class TimeEvent implements Runnable {
|
||||
public void run() {
|
||||
long timePassed;
|
||||
|
||||
//Let's check if more than 10 seconds has passed since the
|
||||
//last time we checked
|
||||
if (System.currentTimeMillis() - lastTime >= 10000) {
|
||||
//set the time passed to the current time minus the last time we checked
|
||||
timePassed = System.currentTimeMillis() - lastTime;
|
||||
lastTime = System.currentTimeMillis();
|
||||
}else {
|
||||
//Less than 10 seconds has past when we last ran this
|
||||
//so let's wait till the next round before we do this
|
||||
return;
|
||||
}
|
||||
|
||||
for(Jail j : pl.getJailManager().getJails()) {
|
||||
for(Prisoner p : j.getAllPrisoners().values()) {
|
||||
//only execute this code if the prisoner's time is more than 0 milliseconds
|
||||
if(p.getRemainingTime() > 0) {
|
||||
Player player = pl.getServer().getPlayer(p.getUUID());
|
||||
|
||||
//Check if the player is offline
|
||||
if(player == null) {
|
||||
//if they are offline AND the config has counting down the time
|
||||
//while the prisoner is offline, then let's do it
|
||||
if(pl.getConfig().getBoolean(Settings.COUNTDOWNTIMEOFFLINE.getPath())) {
|
||||
//Set their remaining time but if it is less than zero, set it to zero
|
||||
p.setRemainingTime(Math.max(0, p.getRemainingTime() - timePassed));
|
||||
if(p.getRemainingTime() == 0) pl.getPrisonerManager().releasePrisoner(player, p);
|
||||
}
|
||||
}else {
|
||||
//The prisoner isn't offline, so let's count down
|
||||
//Set their remaining time but if it is less than zero, set it to zero
|
||||
p.setRemainingTime(Math.max(0, p.getRemainingTime() - timePassed));
|
||||
if(p.getRemainingTime() == 0) pl.getPrisonerManager().releasePrisoner(player, p);
|
||||
|
||||
//Now, let's set and check their afk time
|
||||
//add the time passed to their current afk time
|
||||
try {
|
||||
long afk = Util.getTime(pl.getConfig().getString(Settings.MAXAFKTIME.getPath()));
|
||||
if(afk > 0) {
|
||||
p.setAFKTime(p.getAFKTime() + timePassed);
|
||||
if(p.getAFKTime() > afk) {
|
||||
p.setAFKTime(0);
|
||||
player.kickPlayer(pl.getJailIO().getLanguageString(LangString.AFKKICKMESSAGE));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pl.getLogger().severe("Error while processing the max afk time: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Save all the prisoners and jails after we're done
|
||||
pl.getJailIO().saveJail(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
/**
|
||||
* Contains all the logic for counting down the time of the prisoners time.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
* @version 3.0.0
|
||||
*
|
||||
*/
|
||||
public class JailTimer {
|
||||
private JailMain pl;
|
||||
private Timer timer;
|
||||
private Long lastTime;
|
||||
|
||||
public JailTimer(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
|
||||
this.lastTime = System.currentTimeMillis();
|
||||
if(pl.getConfig().getBoolean(Settings.USEBUKKITTIMER.getPath())) {
|
||||
pl.getLogger().info("Using the Bukkit Scheduler.");
|
||||
pl.getServer().getScheduler().scheduleSyncRepeatingTask(pl, new TimeEvent(), 20, 20);
|
||||
}else {
|
||||
pl.getLogger().info("Using the Java Timer.");
|
||||
timer = new Timer(1000, new ActionListener () {
|
||||
public void actionPerformed (ActionEvent event) {
|
||||
pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new TimeEvent());
|
||||
};
|
||||
});
|
||||
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the instance of this timer. */
|
||||
public Timer getTimer() {
|
||||
return this.timer;
|
||||
}
|
||||
|
||||
class TimeEvent implements Runnable {
|
||||
public void run() {
|
||||
long timePassed;
|
||||
|
||||
//Let's check if more than 10 seconds has passed since the
|
||||
//last time we checked
|
||||
if (System.currentTimeMillis() - lastTime >= 10000) {
|
||||
//set the time passed to the current time minus the last time we checked
|
||||
timePassed = System.currentTimeMillis() - lastTime;
|
||||
lastTime = System.currentTimeMillis();
|
||||
}else {
|
||||
//Less than 10 seconds has past when we last ran this
|
||||
//so let's wait till the next round before we do this
|
||||
return;
|
||||
}
|
||||
|
||||
for(Jail j : pl.getJailManager().getJails()) {
|
||||
for(Prisoner p : j.getAllPrisoners().values()) {
|
||||
//only execute this code if the prisoner's time is more than 0 milliseconds
|
||||
if(p.getRemainingTime() > 0) {
|
||||
Player player = pl.getServer().getPlayer(p.getUUID());
|
||||
|
||||
//Check if the player is offline
|
||||
if(player == null) {
|
||||
//if they are offline AND the config has counting down the time
|
||||
//while the prisoner is offline, then let's do it
|
||||
if(pl.getConfig().getBoolean(Settings.COUNTDOWNTIMEOFFLINE.getPath())) {
|
||||
//Set their remaining time but if it is less than zero, set it to zero
|
||||
p.setRemainingTime(Math.max(0, p.getRemainingTime() - timePassed));
|
||||
if(p.getRemainingTime() == 0) pl.getPrisonerManager().releasePrisoner(player, p);
|
||||
}
|
||||
}else {
|
||||
//The prisoner isn't offline, so let's count down
|
||||
//Set their remaining time but if it is less than zero, set it to zero
|
||||
p.setRemainingTime(Math.max(0, p.getRemainingTime() - timePassed));
|
||||
if(p.getRemainingTime() == 0) pl.getPrisonerManager().releasePrisoner(player, p);
|
||||
|
||||
//Now, let's set and check their afk time
|
||||
//add the time passed to their current afk time
|
||||
try {
|
||||
long afk = Util.getTime(pl.getConfig().getString(Settings.MAXAFKTIME.getPath()));
|
||||
if(afk > 0) {
|
||||
p.setAFKTime(p.getAFKTime() + timePassed);
|
||||
if(p.getAFKTime() > afk) {
|
||||
p.setAFKTime(0);
|
||||
player.kickPlayer(pl.getJailIO().getLanguageString(LangString.AFKKICKMESSAGE));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pl.getLogger().severe("Error while processing the max afk time: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Save all the prisoners and jails after we're done
|
||||
pl.getJailIO().saveJail(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,104 +1,104 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.ScoreboardManager;
|
||||
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class ScoreBoardManager {
|
||||
private JailMain pl;
|
||||
private ScoreboardManager man;
|
||||
private HashMap<UUID, Scoreboard> boards;
|
||||
private OfflinePlayer time;
|
||||
|
||||
public ScoreBoardManager(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.man = plugin.getServer().getScoreboardManager();
|
||||
this.boards = new HashMap<UUID, Scoreboard>();
|
||||
this.time = plugin.getServer().getOfflinePlayer(Util.getColorfulMessage(pl.getConfig().getString(Settings.SCOREBOARDTIME.getPath())));
|
||||
|
||||
//Start the task if it is enabled
|
||||
if(plugin.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
updatePrisonersTime();
|
||||
}
|
||||
}, 200L, 100L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the jailing score board to the player if they don't have one, otherwise it just updates it.
|
||||
*
|
||||
* @param player of whom to add the scoreboard to.
|
||||
* @param pris data for the provided prisoner
|
||||
*/
|
||||
public void addScoreBoard(Player player, Prisoner pris) {
|
||||
if(!boards.containsKey(player.getUniqueId())) {
|
||||
boards.put(player.getUniqueId(), man.getNewScoreboard());
|
||||
Objective o = boards.get(player.getUniqueId()).registerNewObjective("test", "dummy");
|
||||
o.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
o.setDisplayName(Util.getColorfulMessage(pl.getConfig().getString(Settings.SCOREBOARDTITLE.getPath())));
|
||||
o.getScore(time).setScore(pris.getRemainingTimeInMinutesInt());
|
||||
player.setScoreboard(boards.get(player.getUniqueId()));
|
||||
}else {
|
||||
updatePrisonersBoard(player, pris);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player's jail scoreboard for their jail time and sets it to the main one.
|
||||
*
|
||||
* @param player of whom to remove the scoreboard for.
|
||||
*/
|
||||
public void removeScoreBoard(Player player) {
|
||||
boards.remove(player.getUniqueId());
|
||||
//TODO: See if this works or if we need to set it to a new one
|
||||
player.setScoreboard(man.getMainScoreboard());
|
||||
}
|
||||
|
||||
/** Removes all of the scoreboards from the prisoners. */
|
||||
public void removeAllScoreboards() {
|
||||
HashMap<UUID, Scoreboard> temp = new HashMap<UUID, Scoreboard>(boards);
|
||||
|
||||
for(UUID id : temp.keySet()) {
|
||||
Player p = pl.getServer().getPlayer(id);
|
||||
|
||||
if(p != null) {
|
||||
p.setScoreboard(man.getMainScoreboard());
|
||||
}
|
||||
|
||||
boards.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the prisoners time on their scoreboard. */
|
||||
private void updatePrisonersTime() {
|
||||
for(Jail j : pl.getJailManager().getJails()) {
|
||||
for(Prisoner p : j.getAllPrisoners().values()) {
|
||||
if(pl.getServer().getPlayer(p.getUUID()) != null) {
|
||||
addScoreBoard(pl.getServer().getPlayer(p.getUUID()), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a player's time in the scoreboard.
|
||||
*
|
||||
* @param player of whom to update the scoreboard for.
|
||||
* @param pris data for the player
|
||||
*/
|
||||
private void updatePrisonersBoard(Player player, Prisoner pris) {
|
||||
boards.get(player.getUniqueId()).getObjective("test").getScore(time).setScore(pris.getRemainingTimeInMinutesInt());
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.ScoreboardManager;
|
||||
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class ScoreBoardManager {
|
||||
private JailMain pl;
|
||||
private ScoreboardManager man;
|
||||
private HashMap<UUID, Scoreboard> boards;
|
||||
private OfflinePlayer time;
|
||||
|
||||
public ScoreBoardManager(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.man = plugin.getServer().getScoreboardManager();
|
||||
this.boards = new HashMap<UUID, Scoreboard>();
|
||||
this.time = plugin.getServer().getOfflinePlayer(Util.getColorfulMessage(pl.getConfig().getString(Settings.SCOREBOARDTIME.getPath())));
|
||||
|
||||
//Start the task if it is enabled
|
||||
if(plugin.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
updatePrisonersTime();
|
||||
}
|
||||
}, 200L, 100L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the jailing score board to the player if they don't have one, otherwise it just updates it.
|
||||
*
|
||||
* @param player of whom to add the scoreboard to.
|
||||
* @param pris data for the provided prisoner
|
||||
*/
|
||||
public void addScoreBoard(Player player, Prisoner pris) {
|
||||
if(!boards.containsKey(player.getUniqueId())) {
|
||||
boards.put(player.getUniqueId(), man.getNewScoreboard());
|
||||
Objective o = boards.get(player.getUniqueId()).registerNewObjective("test", "dummy");
|
||||
o.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
o.setDisplayName(Util.getColorfulMessage(pl.getConfig().getString(Settings.SCOREBOARDTITLE.getPath())));
|
||||
o.getScore(time).setScore(pris.getRemainingTimeInMinutesInt());
|
||||
player.setScoreboard(boards.get(player.getUniqueId()));
|
||||
}else {
|
||||
updatePrisonersBoard(player, pris);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player's jail scoreboard for their jail time and sets it to the main one.
|
||||
*
|
||||
* @param player of whom to remove the scoreboard for.
|
||||
*/
|
||||
public void removeScoreBoard(Player player) {
|
||||
boards.remove(player.getUniqueId());
|
||||
//TODO: See if this works or if we need to set it to a new one
|
||||
player.setScoreboard(man.getMainScoreboard());
|
||||
}
|
||||
|
||||
/** Removes all of the scoreboards from the prisoners. */
|
||||
public void removeAllScoreboards() {
|
||||
HashMap<UUID, Scoreboard> temp = new HashMap<UUID, Scoreboard>(boards);
|
||||
|
||||
for(UUID id : temp.keySet()) {
|
||||
Player p = pl.getServer().getPlayer(id);
|
||||
|
||||
if(p != null) {
|
||||
p.setScoreboard(man.getMainScoreboard());
|
||||
}
|
||||
|
||||
boards.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the prisoners time on their scoreboard. */
|
||||
private void updatePrisonersTime() {
|
||||
for(Jail j : pl.getJailManager().getJails()) {
|
||||
for(Prisoner p : j.getAllPrisoners().values()) {
|
||||
if(pl.getServer().getPlayer(p.getUUID()) != null) {
|
||||
addScoreBoard(pl.getServer().getPlayer(p.getUUID()), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a player's time in the scoreboard.
|
||||
*
|
||||
* @param player of whom to update the scoreboard for.
|
||||
* @param pris data for the player
|
||||
*/
|
||||
private void updatePrisonersBoard(Player player, Prisoner pris) {
|
||||
boards.get(player.getUniqueId()).getObjective("test").getScore(time).setScore(pris.getRemainingTimeInMinutesInt());
|
||||
}
|
||||
}
|
||||
|
@ -1,334 +1,334 @@
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Provides a variety of methods, static, that are used throughout the plugin.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
* @version 3.0.0
|
||||
*/
|
||||
public class Util {
|
||||
private final static Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)\\s*(m(?:inute)?s?|h(?:ours?)?|d(?:ays?)?|s(?:econd)?s?)?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/**
|
||||
* Checks if the first {@link Vector} is inside this region.
|
||||
*
|
||||
* @param point The point to check
|
||||
* @param first point of the region
|
||||
* @param second second point of the region
|
||||
* @return True if all the coords of the first vector are in the entire region.
|
||||
*/
|
||||
public static boolean isInsideAB(Vector point, Vector first, Vector second) {
|
||||
boolean x = isInside(point.getBlockX(), first.getBlockX(), second.getBlockX());
|
||||
boolean y = isInside(point.getBlockY(), first.getBlockY(), second.getBlockY());
|
||||
boolean z = isInside(point.getBlockZ(), first.getBlockZ(), second.getBlockZ());
|
||||
|
||||
return x && y && z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if two numbers are inside a point, or something.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* @param loc The location.
|
||||
* @param first The first point
|
||||
* @param second The second point
|
||||
* @return true if they are inside, false if not.
|
||||
*/
|
||||
private static boolean isInside(int loc, int first, int second) {
|
||||
int point1 = 0;
|
||||
int point2 = 0;
|
||||
if (first < second) {
|
||||
point1 = first;
|
||||
point2 = second;
|
||||
} else {
|
||||
point2 = first;
|
||||
point1 = second;
|
||||
}
|
||||
|
||||
return (point1 <= loc) && (loc <= point2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string is inside the list, ignoring the casing.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* @param list of strings to check
|
||||
* @param value to check
|
||||
* @return true if the list contains the provided value, false if it doesn't
|
||||
*/
|
||||
public static boolean isStringInsideList(List<String> list, String value) {
|
||||
boolean r = false;
|
||||
for(String s : list)
|
||||
if(s.equalsIgnoreCase(value))
|
||||
return true;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/** Returns a colorful message from the color codes. */
|
||||
public static String getColorfulMessage(String message) {
|
||||
return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1");
|
||||
}
|
||||
|
||||
/** Returns the wand used throughout the different creation steps. */
|
||||
public static ItemStack getWand() {
|
||||
ItemStack wand = new ItemStack(Material.WOOD_SWORD);
|
||||
ItemMeta meta = wand.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.AQUA + "Jail Wand");
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
lore.add(ChatColor.BLUE + "The wand for creating");
|
||||
lore.add(ChatColor.BLUE + "a jail or cell.");
|
||||
meta.setLore(lore);
|
||||
wand.setItemMeta(meta);
|
||||
|
||||
return wand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string like '20minutes' into the appropriate amount of milliseconds.
|
||||
*
|
||||
* @param time The string to convert.
|
||||
* @return The time in milliseconds that is converted.
|
||||
* @throws Exception if there are no matches
|
||||
*/
|
||||
public static Long getTime(String time) throws Exception {
|
||||
if(time.equalsIgnoreCase("-1")) return -1L;
|
||||
|
||||
Long t = 10L;
|
||||
Matcher match = DURATION_PATTERN.matcher(time);
|
||||
|
||||
if (match.matches()) {
|
||||
String units = match.group(2);
|
||||
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.SECONDS);
|
||||
else if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units) || "m".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.MINUTES);
|
||||
else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.HOURS);
|
||||
else if ("days".equals(units) || "day".equals(units) || "d".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.DAYS);
|
||||
else {
|
||||
try {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(time), TimeUnit.MINUTES);
|
||||
}catch(NumberFormatException e) {
|
||||
throw new Exception("Invalid format.");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
throw new Exception("Invalid format.");
|
||||
}
|
||||
|
||||
return Long.valueOf(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player inventory to a String array of Base64 strings. First string is the content and second string is the armor.
|
||||
*
|
||||
* @param playerInventory to turn into an array of strings.
|
||||
* @return Array of strings: [ main content, armor content ]
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public static String[] playerInventoryToBase64(PlayerInventory playerInventory) throws IllegalStateException {
|
||||
//get the main content part, this doesn't return the armor
|
||||
String content = toBase64(playerInventory);
|
||||
String armor = itemStackArrayToBase64(playerInventory.getArmorContents());
|
||||
|
||||
return new String[] { content, armor };
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* A method to serialize an {@link ItemStack} array to Base64 String.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Based off of {@link #toBase64(Inventory)}.
|
||||
*
|
||||
* @param items to turn into a Base64 String.
|
||||
* @return Base64 string of the items.
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(items.length);
|
||||
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
dataOutput.writeObject(items[i]);
|
||||
}
|
||||
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to serialize an inventory to Base64 string.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Special thanks to Comphenix in the Bukkit forums or also known
|
||||
* as aadnk on GitHub.
|
||||
*
|
||||
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
|
||||
*
|
||||
* @param inventory to serialize
|
||||
* @return Base64 string of the provided inventory
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public static String toBase64(Inventory inventory) throws IllegalStateException {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(inventory.getSize());
|
||||
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
dataOutput.writeObject(inventory.getItem(i));
|
||||
}
|
||||
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* A method to get an {@link Inventory} from an encoded, Base64, string.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Special thanks to Comphenix in the Bukkit forums or also known
|
||||
* as aadnk on GitHub.
|
||||
*
|
||||
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
|
||||
*
|
||||
* @param data Base64 string of data containing an inventory.
|
||||
* @return Inventory created from the Base64 string.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Inventory fromBase64(String data) throws IOException {
|
||||
if(data.isEmpty()) Bukkit.getServer().createInventory(null, 0);
|
||||
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
|
||||
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, (ItemStack) dataInput.readObject());
|
||||
}
|
||||
|
||||
dataInput.close();
|
||||
return inventory;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException("Unable to decode class type.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of ItemStacks from Base64 string.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Base off of {@link #fromBase64(String)}.
|
||||
*
|
||||
* @param data Base64 string to convert to ItemStack array.
|
||||
* @return ItemStack array created from the Base64 string.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
|
||||
if(data.isEmpty()) return new ItemStack[] {};
|
||||
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
ItemStack[] items = new ItemStack[dataInput.readInt()];
|
||||
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = (ItemStack) dataInput.readObject();
|
||||
}
|
||||
|
||||
dataInput.close();
|
||||
return items;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException("Unable to decode class type.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreInventory(Player player, Prisoner prisoner) {
|
||||
try {
|
||||
Inventory content = Util.fromBase64(prisoner.getInventory());
|
||||
ItemStack[] armor = Util.itemStackArrayFromBase64(prisoner.getArmor());
|
||||
|
||||
for(ItemStack item : armor) {
|
||||
if(item == null)
|
||||
continue;
|
||||
else if(item.getType().toString().toLowerCase().contains("helmet"))
|
||||
player.getInventory().setHelmet(item);
|
||||
else if(item.getType().toString().toLowerCase().contains("chestplate"))
|
||||
player.getInventory().setChestplate(item);
|
||||
else if(item.getType().toString().toLowerCase().contains("leg"))
|
||||
player.getInventory().setLeggings(item);
|
||||
else if(item.getType().toString().toLowerCase().contains("boots"))
|
||||
player.getInventory().setBoots(item);
|
||||
else if (player.getInventory().firstEmpty() == -1)
|
||||
player.getWorld().dropItem(player.getLocation(), item);
|
||||
else
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
|
||||
for(ItemStack item : content.getContents()) {
|
||||
if(item == null) continue;
|
||||
else if(player.getInventory().firstEmpty() == -1)
|
||||
player.getWorld().dropItem(player.getLocation(), item);
|
||||
else
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getLogger().severe("Unable to restore " + player.getName() + "'s inventory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Provides a variety of methods, static, that are used throughout the plugin.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
* @version 3.0.0
|
||||
*/
|
||||
public class Util {
|
||||
private final static Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)\\s*(m(?:inute)?s?|h(?:ours?)?|d(?:ays?)?|s(?:econd)?s?)?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
/**
|
||||
* Checks if the first {@link Vector} is inside this region.
|
||||
*
|
||||
* @param point The point to check
|
||||
* @param first point of the region
|
||||
* @param second second point of the region
|
||||
* @return True if all the coords of the first vector are in the entire region.
|
||||
*/
|
||||
public static boolean isInsideAB(Vector point, Vector first, Vector second) {
|
||||
boolean x = isInside(point.getBlockX(), first.getBlockX(), second.getBlockX());
|
||||
boolean y = isInside(point.getBlockY(), first.getBlockY(), second.getBlockY());
|
||||
boolean z = isInside(point.getBlockZ(), first.getBlockZ(), second.getBlockZ());
|
||||
|
||||
return x && y && z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if two numbers are inside a point, or something.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* @param loc The location.
|
||||
* @param first The first point
|
||||
* @param second The second point
|
||||
* @return true if they are inside, false if not.
|
||||
*/
|
||||
private static boolean isInside(int loc, int first, int second) {
|
||||
int point1 = 0;
|
||||
int point2 = 0;
|
||||
if (first < second) {
|
||||
point1 = first;
|
||||
point2 = second;
|
||||
} else {
|
||||
point2 = first;
|
||||
point1 = second;
|
||||
}
|
||||
|
||||
return (point1 <= loc) && (loc <= point2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string is inside the list, ignoring the casing.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* @param list of strings to check
|
||||
* @param value to check
|
||||
* @return true if the list contains the provided value, false if it doesn't
|
||||
*/
|
||||
public static boolean isStringInsideList(List<String> list, String value) {
|
||||
boolean r = false;
|
||||
for(String s : list)
|
||||
if(s.equalsIgnoreCase(value))
|
||||
return true;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/** Returns a colorful message from the color codes. */
|
||||
public static String getColorfulMessage(String message) {
|
||||
return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1");
|
||||
}
|
||||
|
||||
/** Returns the wand used throughout the different creation steps. */
|
||||
public static ItemStack getWand() {
|
||||
ItemStack wand = new ItemStack(Material.WOOD_SWORD);
|
||||
ItemMeta meta = wand.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.AQUA + "Jail Wand");
|
||||
LinkedList<String> lore = new LinkedList<String>();
|
||||
lore.add(ChatColor.BLUE + "The wand for creating");
|
||||
lore.add(ChatColor.BLUE + "a jail or cell.");
|
||||
meta.setLore(lore);
|
||||
wand.setItemMeta(meta);
|
||||
|
||||
return wand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string like '20minutes' into the appropriate amount of milliseconds.
|
||||
*
|
||||
* @param time The string to convert.
|
||||
* @return The time in milliseconds that is converted.
|
||||
* @throws Exception if there are no matches
|
||||
*/
|
||||
public static Long getTime(String time) throws Exception {
|
||||
if(time.equalsIgnoreCase("-1")) return -1L;
|
||||
|
||||
Long t = 10L;
|
||||
Matcher match = DURATION_PATTERN.matcher(time);
|
||||
|
||||
if (match.matches()) {
|
||||
String units = match.group(2);
|
||||
if ("seconds".equals(units) || "second".equals(units) || "s".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.SECONDS);
|
||||
else if ("minutes".equals(units) || "minute".equals(units) || "mins".equals(units) || "min".equals(units) || "m".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.MINUTES);
|
||||
else if ("hours".equals(units) || "hour".equals(units) || "h".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.HOURS);
|
||||
else if ("days".equals(units) || "day".equals(units) || "d".equals(units))
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.valueOf(match.group(1)), TimeUnit.DAYS);
|
||||
else {
|
||||
try {
|
||||
t = TimeUnit.MILLISECONDS.convert(Long.parseLong(time), TimeUnit.MINUTES);
|
||||
}catch(NumberFormatException e) {
|
||||
throw new Exception("Invalid format.");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
throw new Exception("Invalid format.");
|
||||
}
|
||||
|
||||
return Long.valueOf(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the player inventory to a String array of Base64 strings. First string is the content and second string is the armor.
|
||||
*
|
||||
* @param playerInventory to turn into an array of strings.
|
||||
* @return Array of strings: [ main content, armor content ]
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public static String[] playerInventoryToBase64(PlayerInventory playerInventory) throws IllegalStateException {
|
||||
//get the main content part, this doesn't return the armor
|
||||
String content = toBase64(playerInventory);
|
||||
String armor = itemStackArrayToBase64(playerInventory.getArmorContents());
|
||||
|
||||
return new String[] { content, armor };
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* A method to serialize an {@link ItemStack} array to Base64 String.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Based off of {@link #toBase64(Inventory)}.
|
||||
*
|
||||
* @param items to turn into a Base64 String.
|
||||
* @return Base64 string of the items.
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public static String itemStackArrayToBase64(ItemStack[] items) throws IllegalStateException {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(items.length);
|
||||
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
dataOutput.writeObject(items[i]);
|
||||
}
|
||||
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to serialize an inventory to Base64 string.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Special thanks to Comphenix in the Bukkit forums or also known
|
||||
* as aadnk on GitHub.
|
||||
*
|
||||
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
|
||||
*
|
||||
* @param inventory to serialize
|
||||
* @return Base64 string of the provided inventory
|
||||
* @throws IllegalStateException
|
||||
*/
|
||||
public static String toBase64(Inventory inventory) throws IllegalStateException {
|
||||
try {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
|
||||
|
||||
// Write the size of the inventory
|
||||
dataOutput.writeInt(inventory.getSize());
|
||||
|
||||
// Save every element in the list
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
dataOutput.writeObject(inventory.getItem(i));
|
||||
}
|
||||
|
||||
// Serialize that array
|
||||
dataOutput.close();
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to save item stacks.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* A method to get an {@link Inventory} from an encoded, Base64, string.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Special thanks to Comphenix in the Bukkit forums or also known
|
||||
* as aadnk on GitHub.
|
||||
*
|
||||
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
|
||||
*
|
||||
* @param data Base64 string of data containing an inventory.
|
||||
* @return Inventory created from the Base64 string.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Inventory fromBase64(String data) throws IOException {
|
||||
if(data.isEmpty()) Bukkit.getServer().createInventory(null, 0);
|
||||
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt());
|
||||
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, (ItemStack) dataInput.readObject());
|
||||
}
|
||||
|
||||
dataInput.close();
|
||||
return inventory;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException("Unable to decode class type.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of ItemStacks from Base64 string.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* Base off of {@link #fromBase64(String)}.
|
||||
*
|
||||
* @param data Base64 string to convert to ItemStack array.
|
||||
* @return ItemStack array created from the Base64 string.
|
||||
* @throws IOException
|
||||
*/
|
||||
public static ItemStack[] itemStackArrayFromBase64(String data) throws IOException {
|
||||
if(data.isEmpty()) return new ItemStack[] {};
|
||||
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
||||
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
|
||||
ItemStack[] items = new ItemStack[dataInput.readInt()];
|
||||
|
||||
// Read the serialized inventory
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = (ItemStack) dataInput.readObject();
|
||||
}
|
||||
|
||||
dataInput.close();
|
||||
return items;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IOException("Unable to decode class type.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void restoreInventory(Player player, Prisoner prisoner) {
|
||||
try {
|
||||
Inventory content = Util.fromBase64(prisoner.getInventory());
|
||||
ItemStack[] armor = Util.itemStackArrayFromBase64(prisoner.getArmor());
|
||||
|
||||
for(ItemStack item : armor) {
|
||||
if(item == null)
|
||||
continue;
|
||||
else if(item.getType().toString().toLowerCase().contains("helmet"))
|
||||
player.getInventory().setHelmet(item);
|
||||
else if(item.getType().toString().toLowerCase().contains("chestplate"))
|
||||
player.getInventory().setChestplate(item);
|
||||
else if(item.getType().toString().toLowerCase().contains("leg"))
|
||||
player.getInventory().setLeggings(item);
|
||||
else if(item.getType().toString().toLowerCase().contains("boots"))
|
||||
player.getInventory().setBoots(item);
|
||||
else if (player.getInventory().firstEmpty() == -1)
|
||||
player.getWorld().dropItem(player.getLocation(), item);
|
||||
else
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
|
||||
for(ItemStack item : content.getContents()) {
|
||||
if(item == null) continue;
|
||||
else if(player.getInventory().firstEmpty() == -1)
|
||||
player.getWorld().dropItem(player.getLocation(), item);
|
||||
else
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getLogger().severe("Unable to restore " + player.getName() + "'s inventory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
/**
|
||||
* An object for storing online cached prisoners.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class CachePrisoner {
|
||||
private Jail jail;
|
||||
private Prisoner p;
|
||||
|
||||
public CachePrisoner(Jail jail, Prisoner prisoner) {
|
||||
this.jail = jail;
|
||||
this.p = prisoner;
|
||||
}
|
||||
|
||||
/** Gets the Jail this cache is in. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the Prisoner in this cache. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.p;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
/**
|
||||
* An object for storing online cached prisoners.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class CachePrisoner {
|
||||
private Jail jail;
|
||||
private Prisoner p;
|
||||
|
||||
public CachePrisoner(Jail jail, Prisoner prisoner) {
|
||||
this.jail = jail;
|
||||
this.p = prisoner;
|
||||
}
|
||||
|
||||
/** Gets the Jail this cache is in. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the Prisoner in this cache. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.p;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,44 @@
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
|
||||
/**
|
||||
* Holds data for when a player is confirming a command.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 1.0.0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class ConfirmPlayer {
|
||||
private String name;
|
||||
private String[] args;
|
||||
private Confirmation confirm;
|
||||
private Long expires;
|
||||
|
||||
public ConfirmPlayer(String name, String[] args, Confirmation confirm) {
|
||||
this.name = name;
|
||||
this.args = args;
|
||||
this.confirm = confirm;
|
||||
this.expires = System.currentTimeMillis() + 5000L;
|
||||
}
|
||||
|
||||
/** Returns the name of the thing needing to confirm. */
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Returns the initial arguments they sent with their command. */
|
||||
public String[] getArguments() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
/** Returns what they are {@link Confirmation confirming}. */
|
||||
public Confirmation getConfirming() {
|
||||
return this.confirm;
|
||||
}
|
||||
|
||||
/** Returns the time in milliseconds their confirmation time frame expires. */
|
||||
public Long getExpiryTime() {
|
||||
return this.expires;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
|
||||
/**
|
||||
* Holds data for when a player is confirming a command.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 1.0.0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class ConfirmPlayer {
|
||||
private String name;
|
||||
private String[] args;
|
||||
private Confirmation confirm;
|
||||
private Long expires;
|
||||
|
||||
public ConfirmPlayer(String name, String[] args, Confirmation confirm) {
|
||||
this.name = name;
|
||||
this.args = args;
|
||||
this.confirm = confirm;
|
||||
this.expires = System.currentTimeMillis() + 5000L;
|
||||
}
|
||||
|
||||
/** Returns the name of the thing needing to confirm. */
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Returns the initial arguments they sent with their command. */
|
||||
public String[] getArguments() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
/** Returns what they are {@link Confirmation confirming}. */
|
||||
public Confirmation getConfirming() {
|
||||
return this.confirm;
|
||||
}
|
||||
|
||||
/** Returns the time in milliseconds their confirmation time frame expires. */
|
||||
public Long getExpiryTime() {
|
||||
return this.expires;
|
||||
}
|
||||
}
|
||||
|
@ -1,382 +1,382 @@
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
|
||||
/** Represents a Jail, contains the prisoners and the cells.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.3
|
||||
*/
|
||||
public class Jail {
|
||||
private JailMain plugin;
|
||||
private HashMap<String, Cell> cells;
|
||||
private HashMap<UUID, Prisoner> nocellPrisoners;//prisoners who aren't in a cell
|
||||
private String name = "", world = "";
|
||||
private int minX, minY, minZ, maxX, maxY, maxZ;
|
||||
private Location in, free;
|
||||
|
||||
public Jail(JailMain plugin, String name) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
cells = new HashMap<String, Cell>();
|
||||
nocellPrisoners = new HashMap<UUID, Prisoner>();
|
||||
}
|
||||
|
||||
/** Gets the instance of the plugin's main class. */
|
||||
public JailMain getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
/** Sets the name of the jail. */
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/** Gets the name of the jail. */
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Sets the location of the <b>minimum</b> point to the given location's coordinates. */
|
||||
public void setMinPoint(Location location) {
|
||||
if(this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
|
||||
this.minX = location.getBlockX();
|
||||
this.minY = location.getBlockY();
|
||||
this.minZ = location.getBlockZ();
|
||||
}
|
||||
|
||||
/** Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>. */
|
||||
public void setMinPoint(int[] coords) {
|
||||
if(coords.length != 3) return;
|
||||
|
||||
this.minX = coords[0];
|
||||
this.minY = coords[1];
|
||||
this.minZ = coords[2];
|
||||
}
|
||||
|
||||
/** Gets the minimum point as a Bukkit Location class. */
|
||||
public Location getMinPoint() {
|
||||
return new Location(plugin.getServer().getWorld(world), minX, minY, minZ);
|
||||
}
|
||||
|
||||
/** Sets the location of the <b>maximum</b> point to the given location's coordinates. */
|
||||
public void setMaxPoint(Location location) {
|
||||
if(this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
|
||||
this.maxX = location.getBlockX();
|
||||
this.maxY = location.getBlockY();
|
||||
this.maxZ = location.getBlockZ();
|
||||
}
|
||||
|
||||
/** Gets the minimum point as a Bukkit Location class. */
|
||||
public Location getMaxPoint() {
|
||||
return new Location(plugin.getServer().getWorld(world), maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
/** Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>. */
|
||||
public void setMaxPoint(int[] coords) {
|
||||
if(coords.length != 3) return;
|
||||
|
||||
this.maxX = coords[0];
|
||||
this.maxY = coords[1];
|
||||
this.maxZ = coords[2];
|
||||
}
|
||||
|
||||
/** Sets the name of the world this Jail is in. */
|
||||
public void setWorld(String name) {
|
||||
this.world = name;
|
||||
}
|
||||
|
||||
/** Gets the name of the world this Jail is in. */
|
||||
public String getWorldName() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/** Gets the instance of the {@link World world} this Jail is in. */
|
||||
public World getWorld() {
|
||||
return plugin.getServer().getWorld(world);
|
||||
}
|
||||
|
||||
/** Sets the {@link Location location} of the teleport <strong>in</strong>. */
|
||||
public void setTeleportIn(Location location) {
|
||||
if(this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
|
||||
this.in = location;
|
||||
}
|
||||
|
||||
/** Gets the {@link Location location} of the teleport in. */
|
||||
public Location getTeleportIn() {
|
||||
return this.in;
|
||||
}
|
||||
|
||||
/** Sets the {@link Location location} of the teleport for the <strong>free</strong> spot. */
|
||||
public void setTeleportFree(Location location) {
|
||||
this.free = location;
|
||||
}
|
||||
|
||||
/** Gets the {@link Location location} of the teleport free spot.*/
|
||||
public Location getTeleportFree() {
|
||||
return this.free;
|
||||
}
|
||||
|
||||
/** Add a prisoner to this jail. */
|
||||
public void addPrisoner(Prisoner p) {
|
||||
this.nocellPrisoners.put(p.getUUID(), p);
|
||||
}
|
||||
|
||||
/** Removes a prisoner from this jail, doesn't remove it from the cell. */
|
||||
public void removePrisoner(Prisoner p) {
|
||||
this.nocellPrisoners.remove(p);
|
||||
}
|
||||
|
||||
/** Adds a cell to the Jail. */
|
||||
public void addCell(Cell cell, boolean save) {
|
||||
if(save) plugin.getJailIO().saveCell(this, cell);
|
||||
this.cells.put(cell.getName(), cell);
|
||||
}
|
||||
|
||||
/** Gets the cell with the given name. */
|
||||
public Cell getCell(String name) {
|
||||
return this.cells.get(name);
|
||||
}
|
||||
|
||||
/** Checks if the given name is a valid cell. */
|
||||
public boolean isValidCell(String name) {
|
||||
return this.cells.get(name) != null;
|
||||
}
|
||||
|
||||
/** Removes the cell from the jail. */
|
||||
public void removeCell(String name) {
|
||||
Cell c = this.cells.get(name);
|
||||
//If we have a chest, clear the inventory
|
||||
if(c.hasChest()) {
|
||||
c.getChest().getInventory().clear();
|
||||
}
|
||||
|
||||
//For each sign, clear the lines on the sign
|
||||
for(SimpleLocation s : c.getSigns()) {
|
||||
if(s.getLocation().getBlock() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock();
|
||||
for(int i = 0; i < 4; i++) {
|
||||
sign.setLine(i, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove the information from the storage first as it requires an instance
|
||||
plugin.getJailIO().removeCell(this, c);
|
||||
//now remove it from the local storage
|
||||
this.cells.remove(name);
|
||||
}
|
||||
|
||||
/** Returns the cell which the given player name is jailed in, null if not. */
|
||||
public Cell getCellPrisonerIsIn(UUID uuid) {
|
||||
for(Cell c : cells.values())
|
||||
if(c.hasPrisoner())
|
||||
if(c.getPrisoner().getUUID().equals(uuid))
|
||||
return c;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Returns the first empty cell, returns null if there aren't any cells or any free cells. */
|
||||
public Cell getFirstEmptyCell() {
|
||||
for(Cell c : getCells())
|
||||
if(c.hasPrisoner())
|
||||
continue;
|
||||
else
|
||||
return c;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Gets the amount of cells the jail. */
|
||||
public int getCellCount() {
|
||||
return this.cells.size();
|
||||
}
|
||||
|
||||
/** Gets all the cells in the jail. */
|
||||
public HashSet<Cell> getCells() {
|
||||
return new HashSet<Cell>(this.cells.values());
|
||||
}
|
||||
|
||||
/** Gets the closest cell to the provided location, via the teleport in location of the cells. */
|
||||
public Cell getNearestCell(Location loc) {
|
||||
Cell cell = null;
|
||||
double distance = -1;
|
||||
|
||||
for(Cell c : getCells()) {
|
||||
//Check if the worlds are the same, if not we can't calculate anything
|
||||
if(c.getTeleport().getWorld().getName().equalsIgnoreCase(loc.getWorld().getName())) {
|
||||
//They are in the same world
|
||||
double dist = c.getTeleport().distance(loc);
|
||||
if (dist < distance || distance < 0) {
|
||||
cell = c;
|
||||
distance = dist;
|
||||
}
|
||||
}else {
|
||||
//If they aren't, return the first cell found.
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
/** Clears all the prisoners from this Jail. */
|
||||
public void clearPrisoners() {
|
||||
//Remove the prisoners from all the cells
|
||||
for(Cell c : getCells()) {
|
||||
c.removePrisoner();
|
||||
}
|
||||
|
||||
//Replace all the current no cell prisoners with
|
||||
//a new hashset of prisoners.
|
||||
this.nocellPrisoners = new HashMap<UUID, Prisoner>();
|
||||
}
|
||||
|
||||
/** Gets a HashMap of <b>all</b> the prisoners, the ones in cells and ones who aren't. */
|
||||
public HashMap<UUID, Prisoner> getAllPrisoners() {
|
||||
HashMap<UUID, Prisoner> all = new HashMap<UUID, Prisoner>(nocellPrisoners); //initalize the temp one to return with the prisoners not in any cells
|
||||
|
||||
for(Cell c : cells.values())
|
||||
if(c.hasPrisoner())
|
||||
all.put(c.getPrisoner().getUUID(), c.getPrisoner());
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
/** Gets a HashSet of the prisoners <b>in cells</b>. */
|
||||
public HashSet<Prisoner> getPrisonersInCells() {
|
||||
HashSet<Prisoner> all = new HashSet<Prisoner>();
|
||||
|
||||
for(Cell c : getCells())
|
||||
if(c.hasPrisoner())
|
||||
all.add(c.getPrisoner());
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
/** Gets a HashSet of the prisoners <b>not</b> in cells.*/
|
||||
public HashMap<UUID, Prisoner> getPrisonersNotInCells() {
|
||||
return this.nocellPrisoners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the player is a prisoner in the system, whether in a cell or no cell.
|
||||
*
|
||||
* @param player The {@link Player player instance} of the person we're checking.
|
||||
* @return true if is jailed, false if not.
|
||||
*/
|
||||
public boolean isPlayerJailed(Player player) {
|
||||
return this.isPlayerAPrisoner(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the uuid of a player is a prisoner in the system, whether in a cell or no cell.
|
||||
*
|
||||
* @param uuid The uuid of the person we're checking.
|
||||
* @return true if is jailed, false if not.
|
||||
*/
|
||||
public boolean isPlayerJailed(UUID uuid) {
|
||||
return this.isPlayerAPrisoner(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the uuid of a player is a prisoner in this jail, no matter if they're in a cell or not.
|
||||
*
|
||||
* @param uuid The name of the person we're checking.
|
||||
* @return true if is a prisoner, false if not.
|
||||
*/
|
||||
private boolean isPlayerAPrisoner(UUID uuid) {
|
||||
return this.getAllPrisoners().containsKey(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given uuid of a player is a prisoner in a cell.
|
||||
*
|
||||
* @param uuid of the prisoner to check.
|
||||
* @return true if is jailed in a cell, false if not.
|
||||
*/
|
||||
public boolean isJailedInACell(UUID uuid) {
|
||||
if(this.nocellPrisoners.containsKey(uuid)) return false;
|
||||
|
||||
for(Cell c : cells.values())
|
||||
if(c.getPrisoner() != null)
|
||||
if(c.getPrisoner().getUUID().equals(uuid))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Prisoner prisoner} instance for the given name.
|
||||
*
|
||||
* @param name The name of the prisoner to get.
|
||||
* @return the prisoner instance, can be null
|
||||
*/
|
||||
public Prisoner getPrisonerByLastKnownName(String name) {
|
||||
for(Prisoner p : this.getAllPrisoners().values())
|
||||
if(p.getLastKnownName().equalsIgnoreCase(name))
|
||||
return p;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Prisoner prisoner} instance for the given uuid.
|
||||
*
|
||||
* @param uuid The uuid of the prisoner to get.
|
||||
* @return the prisoner instance, can be null
|
||||
*/
|
||||
public Prisoner getPrisoner(UUID uuid) {
|
||||
if(this.nocellPrisoners.containsKey(uuid)) return this.nocellPrisoners.get(uuid);
|
||||
|
||||
for(Cell c : cells.values())
|
||||
if(c.hasPrisoner())
|
||||
if(c.getPrisoner().getUUID().equals(uuid))
|
||||
return c.getPrisoner();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the squared distance between teleport location of this jail
|
||||
* and specified location in blocks. If locations are not in same world,
|
||||
* distance cannot be calculated and it will return Integer.MAX_VALUE.
|
||||
*
|
||||
* @param loc The location to check
|
||||
* @return Distance between the location provided and the teleport in location.
|
||||
*/
|
||||
public double getDistance(Location loc) {
|
||||
if (loc.getWorld().getName().equalsIgnoreCase(getTeleportIn().getWorld().getName())) return (double) Integer.MAX_VALUE;
|
||||
else return loc.distance(getTeleportIn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given location is inside this Jail.
|
||||
*
|
||||
* @param loc to check whether is inside this jail
|
||||
* @return True if the location is in the jail, false if it isn't
|
||||
*/
|
||||
public boolean isInside(Location loc) {
|
||||
if(loc.getWorld().getName().equalsIgnoreCase(world)) {
|
||||
return Util.isInsideAB(loc.toVector(), new Vector(minX, minY, minZ), new Vector(maxX, maxY, maxZ));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
|
||||
/** Represents a Jail, contains the prisoners and the cells.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.3
|
||||
*/
|
||||
public class Jail {
|
||||
private JailMain plugin;
|
||||
private HashMap<String, Cell> cells;
|
||||
private HashMap<UUID, Prisoner> nocellPrisoners;//prisoners who aren't in a cell
|
||||
private String name = "", world = "";
|
||||
private int minX, minY, minZ, maxX, maxY, maxZ;
|
||||
private Location in, free;
|
||||
|
||||
public Jail(JailMain plugin, String name) {
|
||||
this.plugin = plugin;
|
||||
this.name = name;
|
||||
cells = new HashMap<String, Cell>();
|
||||
nocellPrisoners = new HashMap<UUID, Prisoner>();
|
||||
}
|
||||
|
||||
/** Gets the instance of the plugin's main class. */
|
||||
public JailMain getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
/** Sets the name of the jail. */
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/** Gets the name of the jail. */
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Sets the location of the <b>minimum</b> point to the given location's coordinates. */
|
||||
public void setMinPoint(Location location) {
|
||||
if(this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
|
||||
this.minX = location.getBlockX();
|
||||
this.minY = location.getBlockY();
|
||||
this.minZ = location.getBlockZ();
|
||||
}
|
||||
|
||||
/** Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>. */
|
||||
public void setMinPoint(int[] coords) {
|
||||
if(coords.length != 3) return;
|
||||
|
||||
this.minX = coords[0];
|
||||
this.minY = coords[1];
|
||||
this.minZ = coords[2];
|
||||
}
|
||||
|
||||
/** Gets the minimum point as a Bukkit Location class. */
|
||||
public Location getMinPoint() {
|
||||
return new Location(plugin.getServer().getWorld(world), minX, minY, minZ);
|
||||
}
|
||||
|
||||
/** Sets the location of the <b>maximum</b> point to the given location's coordinates. */
|
||||
public void setMaxPoint(Location location) {
|
||||
if(this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
|
||||
this.maxX = location.getBlockX();
|
||||
this.maxY = location.getBlockY();
|
||||
this.maxZ = location.getBlockZ();
|
||||
}
|
||||
|
||||
/** Gets the minimum point as a Bukkit Location class. */
|
||||
public Location getMaxPoint() {
|
||||
return new Location(plugin.getServer().getWorld(world), maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
/** Accepts an array of ints as the coord, where <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong>. */
|
||||
public void setMaxPoint(int[] coords) {
|
||||
if(coords.length != 3) return;
|
||||
|
||||
this.maxX = coords[0];
|
||||
this.maxY = coords[1];
|
||||
this.maxZ = coords[2];
|
||||
}
|
||||
|
||||
/** Sets the name of the world this Jail is in. */
|
||||
public void setWorld(String name) {
|
||||
this.world = name;
|
||||
}
|
||||
|
||||
/** Gets the name of the world this Jail is in. */
|
||||
public String getWorldName() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/** Gets the instance of the {@link World world} this Jail is in. */
|
||||
public World getWorld() {
|
||||
return plugin.getServer().getWorld(world);
|
||||
}
|
||||
|
||||
/** Sets the {@link Location location} of the teleport <strong>in</strong>. */
|
||||
public void setTeleportIn(Location location) {
|
||||
if(this.world.isEmpty()) this.world = location.getWorld().getName();
|
||||
|
||||
this.in = location;
|
||||
}
|
||||
|
||||
/** Gets the {@link Location location} of the teleport in. */
|
||||
public Location getTeleportIn() {
|
||||
return this.in;
|
||||
}
|
||||
|
||||
/** Sets the {@link Location location} of the teleport for the <strong>free</strong> spot. */
|
||||
public void setTeleportFree(Location location) {
|
||||
this.free = location;
|
||||
}
|
||||
|
||||
/** Gets the {@link Location location} of the teleport free spot.*/
|
||||
public Location getTeleportFree() {
|
||||
return this.free;
|
||||
}
|
||||
|
||||
/** Add a prisoner to this jail. */
|
||||
public void addPrisoner(Prisoner p) {
|
||||
this.nocellPrisoners.put(p.getUUID(), p);
|
||||
}
|
||||
|
||||
/** Removes a prisoner from this jail, doesn't remove it from the cell. */
|
||||
public void removePrisoner(Prisoner p) {
|
||||
this.nocellPrisoners.remove(p);
|
||||
}
|
||||
|
||||
/** Adds a cell to the Jail. */
|
||||
public void addCell(Cell cell, boolean save) {
|
||||
if(save) plugin.getJailIO().saveCell(this, cell);
|
||||
this.cells.put(cell.getName(), cell);
|
||||
}
|
||||
|
||||
/** Gets the cell with the given name. */
|
||||
public Cell getCell(String name) {
|
||||
return this.cells.get(name);
|
||||
}
|
||||
|
||||
/** Checks if the given name is a valid cell. */
|
||||
public boolean isValidCell(String name) {
|
||||
return this.cells.get(name) != null;
|
||||
}
|
||||
|
||||
/** Removes the cell from the jail. */
|
||||
public void removeCell(String name) {
|
||||
Cell c = this.cells.get(name);
|
||||
//If we have a chest, clear the inventory
|
||||
if(c.hasChest()) {
|
||||
c.getChest().getInventory().clear();
|
||||
}
|
||||
|
||||
//For each sign, clear the lines on the sign
|
||||
for(SimpleLocation s : c.getSigns()) {
|
||||
if(s.getLocation().getBlock() instanceof Sign) {
|
||||
Sign sign = (Sign) s.getLocation().getBlock();
|
||||
for(int i = 0; i < 4; i++) {
|
||||
sign.setLine(i, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove the information from the storage first as it requires an instance
|
||||
plugin.getJailIO().removeCell(this, c);
|
||||
//now remove it from the local storage
|
||||
this.cells.remove(name);
|
||||
}
|
||||
|
||||
/** Returns the cell which the given player name is jailed in, null if not. */
|
||||
public Cell getCellPrisonerIsIn(UUID uuid) {
|
||||
for(Cell c : cells.values())
|
||||
if(c.hasPrisoner())
|
||||
if(c.getPrisoner().getUUID().equals(uuid))
|
||||
return c;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Returns the first empty cell, returns null if there aren't any cells or any free cells. */
|
||||
public Cell getFirstEmptyCell() {
|
||||
for(Cell c : getCells())
|
||||
if(c.hasPrisoner())
|
||||
continue;
|
||||
else
|
||||
return c;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Gets the amount of cells the jail. */
|
||||
public int getCellCount() {
|
||||
return this.cells.size();
|
||||
}
|
||||
|
||||
/** Gets all the cells in the jail. */
|
||||
public HashSet<Cell> getCells() {
|
||||
return new HashSet<Cell>(this.cells.values());
|
||||
}
|
||||
|
||||
/** Gets the closest cell to the provided location, via the teleport in location of the cells. */
|
||||
public Cell getNearestCell(Location loc) {
|
||||
Cell cell = null;
|
||||
double distance = -1;
|
||||
|
||||
for(Cell c : getCells()) {
|
||||
//Check if the worlds are the same, if not we can't calculate anything
|
||||
if(c.getTeleport().getWorld().getName().equalsIgnoreCase(loc.getWorld().getName())) {
|
||||
//They are in the same world
|
||||
double dist = c.getTeleport().distance(loc);
|
||||
if (dist < distance || distance < 0) {
|
||||
cell = c;
|
||||
distance = dist;
|
||||
}
|
||||
}else {
|
||||
//If they aren't, return the first cell found.
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
/** Clears all the prisoners from this Jail. */
|
||||
public void clearPrisoners() {
|
||||
//Remove the prisoners from all the cells
|
||||
for(Cell c : getCells()) {
|
||||
c.removePrisoner();
|
||||
}
|
||||
|
||||
//Replace all the current no cell prisoners with
|
||||
//a new hashset of prisoners.
|
||||
this.nocellPrisoners = new HashMap<UUID, Prisoner>();
|
||||
}
|
||||
|
||||
/** Gets a HashMap of <b>all</b> the prisoners, the ones in cells and ones who aren't. */
|
||||
public HashMap<UUID, Prisoner> getAllPrisoners() {
|
||||
HashMap<UUID, Prisoner> all = new HashMap<UUID, Prisoner>(nocellPrisoners); //initalize the temp one to return with the prisoners not in any cells
|
||||
|
||||
for(Cell c : cells.values())
|
||||
if(c.hasPrisoner())
|
||||
all.put(c.getPrisoner().getUUID(), c.getPrisoner());
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
/** Gets a HashSet of the prisoners <b>in cells</b>. */
|
||||
public HashSet<Prisoner> getPrisonersInCells() {
|
||||
HashSet<Prisoner> all = new HashSet<Prisoner>();
|
||||
|
||||
for(Cell c : getCells())
|
||||
if(c.hasPrisoner())
|
||||
all.add(c.getPrisoner());
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
/** Gets a HashSet of the prisoners <b>not</b> in cells.*/
|
||||
public HashMap<UUID, Prisoner> getPrisonersNotInCells() {
|
||||
return this.nocellPrisoners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the player is a prisoner in the system, whether in a cell or no cell.
|
||||
*
|
||||
* @param player The {@link Player player instance} of the person we're checking.
|
||||
* @return true if is jailed, false if not.
|
||||
*/
|
||||
public boolean isPlayerJailed(Player player) {
|
||||
return this.isPlayerAPrisoner(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the uuid of a player is a prisoner in the system, whether in a cell or no cell.
|
||||
*
|
||||
* @param uuid The uuid of the person we're checking.
|
||||
* @return true if is jailed, false if not.
|
||||
*/
|
||||
public boolean isPlayerJailed(UUID uuid) {
|
||||
return this.isPlayerAPrisoner(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the uuid of a player is a prisoner in this jail, no matter if they're in a cell or not.
|
||||
*
|
||||
* @param uuid The name of the person we're checking.
|
||||
* @return true if is a prisoner, false if not.
|
||||
*/
|
||||
private boolean isPlayerAPrisoner(UUID uuid) {
|
||||
return this.getAllPrisoners().containsKey(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given uuid of a player is a prisoner in a cell.
|
||||
*
|
||||
* @param uuid of the prisoner to check.
|
||||
* @return true if is jailed in a cell, false if not.
|
||||
*/
|
||||
public boolean isJailedInACell(UUID uuid) {
|
||||
if(this.nocellPrisoners.containsKey(uuid)) return false;
|
||||
|
||||
for(Cell c : cells.values())
|
||||
if(c.getPrisoner() != null)
|
||||
if(c.getPrisoner().getUUID().equals(uuid))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Prisoner prisoner} instance for the given name.
|
||||
*
|
||||
* @param name The name of the prisoner to get.
|
||||
* @return the prisoner instance, can be null
|
||||
*/
|
||||
public Prisoner getPrisonerByLastKnownName(String name) {
|
||||
for(Prisoner p : this.getAllPrisoners().values())
|
||||
if(p.getLastKnownName().equalsIgnoreCase(name))
|
||||
return p;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Prisoner prisoner} instance for the given uuid.
|
||||
*
|
||||
* @param uuid The uuid of the prisoner to get.
|
||||
* @return the prisoner instance, can be null
|
||||
*/
|
||||
public Prisoner getPrisoner(UUID uuid) {
|
||||
if(this.nocellPrisoners.containsKey(uuid)) return this.nocellPrisoners.get(uuid);
|
||||
|
||||
for(Cell c : cells.values())
|
||||
if(c.hasPrisoner())
|
||||
if(c.getPrisoner().getUUID().equals(uuid))
|
||||
return c.getPrisoner();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the squared distance between teleport location of this jail
|
||||
* and specified location in blocks. If locations are not in same world,
|
||||
* distance cannot be calculated and it will return Integer.MAX_VALUE.
|
||||
*
|
||||
* @param loc The location to check
|
||||
* @return Distance between the location provided and the teleport in location.
|
||||
*/
|
||||
public double getDistance(Location loc) {
|
||||
if (loc.getWorld().getName().equalsIgnoreCase(getTeleportIn().getWorld().getName())) return (double) Integer.MAX_VALUE;
|
||||
else return loc.distance(getTeleportIn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given location is inside this Jail.
|
||||
*
|
||||
* @param loc to check whether is inside this jail
|
||||
* @return True if the location is in the jail, false if it isn't
|
||||
*/
|
||||
public boolean isInside(Location loc) {
|
||||
if(loc.getWorld().getName().equalsIgnoreCase(world)) {
|
||||
return Util.isInsideAB(loc.toVector(), new Vector(minX, minY, minZ), new Vector(maxX, maxY, maxZ));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,254 +1,254 @@
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
* @version 3.0.1
|
||||
*/
|
||||
public class Prisoner {
|
||||
private String uuid, name, jailer, reason, inventory, armor;
|
||||
private boolean muted, offlinePending, teleporting, toBeTransferred;
|
||||
private long time, afk;
|
||||
private Location previousPosition;
|
||||
private GameMode previousGameMode;
|
||||
|
||||
/**
|
||||
* Creates a new prisoner with a name and whether they are muted or not.
|
||||
*
|
||||
* @param uuid The uuid of the prisoner
|
||||
* @param name The name of the prisoner
|
||||
* @param muted Whether the prisoner is muted or not
|
||||
* @param time The amount of remaining time the prisoner has
|
||||
* @param jailer The name of the person who jailed this prisoner
|
||||
* @param reason The reason why this prisoner is in jail
|
||||
*/
|
||||
public Prisoner(String uuid, String name, boolean muted, long time, String jailer, String reason) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.muted = muted;
|
||||
this.time = time;
|
||||
this.jailer = jailer;
|
||||
this.reason = reason;
|
||||
this.offlinePending = false;
|
||||
this.teleporting = false;
|
||||
this.toBeTransferred = false;
|
||||
this.previousPosition = null;
|
||||
this.previousGameMode = GameMode.SURVIVAL;
|
||||
this.inventory = "";
|
||||
this.armor = "";
|
||||
this.afk = 0;
|
||||
}
|
||||
|
||||
/** Returns the UUID of the prisoner. */
|
||||
public UUID getUUID() {
|
||||
return UUID.fromString(this.uuid);
|
||||
}
|
||||
|
||||
/** Gets the name of this prisoner. */
|
||||
public String getLastKnownName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Sets the name of this prisoner. */
|
||||
public String setLastKnownName(String username) {
|
||||
this.name = username;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Gets the reason this player was jailed for. */
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
/** Sets the reason this player was jailed for. */
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/** Gets the person who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.jailer;
|
||||
}
|
||||
|
||||
/** Sets the person who jailed this prisoner. */
|
||||
public void setJailer(String jailer) {
|
||||
this.jailer = jailer;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner is muted or not. */
|
||||
public boolean isMuted() {
|
||||
return this.muted;
|
||||
}
|
||||
|
||||
/** Sets whether the prisoner is muted or not. */
|
||||
public void setMuted(boolean muted) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prisoner has. */
|
||||
public long getRemainingTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prisoner has in minutes. */
|
||||
public long getRemainingTimeInMinutes() {
|
||||
return TimeUnit.MINUTES.convert(time, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prison has in minutes except only in int format. */
|
||||
public int getRemainingTimeInMinutesInt() {
|
||||
return (int) this.getRemainingTimeInMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the remaining time the prisoner has left.
|
||||
*
|
||||
* @param time The amount of time left, in milliseconds.
|
||||
*/
|
||||
public void setRemainingTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given time to the remaining time the prisoner has left.
|
||||
*
|
||||
* @param time to add to the prisoner's remaining time.
|
||||
* @return the new remaining time the prisoner has
|
||||
*/
|
||||
public long addTime(long time) {
|
||||
this.time += time;
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts the given time from the remaining time the prisoner has left.
|
||||
*
|
||||
* @param time to subtract from the prisoner's remaining time.
|
||||
* @return the new remaining time the prisoner has
|
||||
*/
|
||||
public long subtractTime(long time) {
|
||||
this.time -= time;
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/** Gets whether the player is offline or not. */
|
||||
public boolean isOfflinePending() {
|
||||
return this.offlinePending;
|
||||
}
|
||||
|
||||
/** Sets whether the player is offline or not. */
|
||||
public void setOfflinePending(boolean offline) {
|
||||
this.offlinePending = offline;
|
||||
}
|
||||
|
||||
/** Gets whether the player is being teleported or not. */
|
||||
public boolean isTeleporting() {
|
||||
return this.teleporting;
|
||||
}
|
||||
|
||||
/** Sets whether the player is being teleported or not. */
|
||||
public void setTeleporting(boolean teleport) {
|
||||
this.teleporting = teleport;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
||||
public boolean isToBeTransferred() {
|
||||
return this.toBeTransferred;
|
||||
}
|
||||
|
||||
/** Sets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
||||
public void setToBeTransferred(boolean transferred) {
|
||||
this.toBeTransferred = transferred;
|
||||
}
|
||||
|
||||
/** Gets the previous location of this player, can be null. */
|
||||
public Location getPreviousLocation() {
|
||||
return this.previousPosition;
|
||||
}
|
||||
|
||||
/** Gets the previous location of this player, separated by a comma. */
|
||||
public String getPreviousLocationString() {
|
||||
if(previousPosition == null) return "";
|
||||
else return previousPosition.getWorld().getName() + "," +
|
||||
previousPosition.getX() + "," +
|
||||
previousPosition.getY() + "," +
|
||||
previousPosition.getZ() + "," +
|
||||
previousPosition.getYaw() + "," +
|
||||
previousPosition.getPitch();
|
||||
}
|
||||
|
||||
/** Sets the previous location of this player. */
|
||||
public void setPreviousPosition(Location location) {
|
||||
this.previousPosition = location;
|
||||
}
|
||||
|
||||
/** Sets the previous location of this player from a comma separated string. */
|
||||
public void setPreviousPosition(String location) {
|
||||
if(location == null) return;
|
||||
if(location.isEmpty()) return;
|
||||
|
||||
String[] s = location.split(",");
|
||||
this.previousPosition = new Location(Bukkit.getWorld(s[0]),
|
||||
Double.valueOf(s[1]),
|
||||
Double.valueOf(s[2]),
|
||||
Double.valueOf(s[3]),
|
||||
Float.valueOf(s[4]),
|
||||
Float.valueOf(s[5]));
|
||||
}
|
||||
|
||||
/** Gets the previous gamemode of this player. */
|
||||
public GameMode getPreviousGameMode() {
|
||||
return this.previousGameMode;
|
||||
}
|
||||
|
||||
/** Sets the previous gamemode of this player. */
|
||||
public void setPreviousGameMode(GameMode previous) {
|
||||
this.previousGameMode = previous;
|
||||
}
|
||||
|
||||
/** Sets the previous gamemode of this player based upon the provided string. */
|
||||
public void setPreviousGameMode(String previous) {
|
||||
if(previous == null) return;
|
||||
else if(previous.isEmpty()) return;
|
||||
else this.previousGameMode = GameMode.valueOf(previous);
|
||||
}
|
||||
|
||||
/** Gets the inventory string for this player, it is encoded in Base64 string. */
|
||||
public String getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
/** Sets the inventory Base64 string. */
|
||||
public void setInventory(String inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
/** Gets the armor content, encoded in Base64 string. */
|
||||
public String getArmor() {
|
||||
return this.armor;
|
||||
}
|
||||
|
||||
/** Sets the armor inventory Base64 string. */
|
||||
public void setArmor(String armor) {
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
/** Gets the time, in milliseconds, this prisoner has been afk. */
|
||||
public long getAFKTime() {
|
||||
return this.afk;
|
||||
}
|
||||
|
||||
/** Sets the time, in milliseconds, this prisoner has been afk. */
|
||||
public void setAFKTime(long time) {
|
||||
this.afk = time;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 2.x.x
|
||||
* @version 3.0.1
|
||||
*/
|
||||
public class Prisoner {
|
||||
private String uuid, name, jailer, reason, inventory, armor;
|
||||
private boolean muted, offlinePending, teleporting, toBeTransferred;
|
||||
private long time, afk;
|
||||
private Location previousPosition;
|
||||
private GameMode previousGameMode;
|
||||
|
||||
/**
|
||||
* Creates a new prisoner with a name and whether they are muted or not.
|
||||
*
|
||||
* @param uuid The uuid of the prisoner
|
||||
* @param name The name of the prisoner
|
||||
* @param muted Whether the prisoner is muted or not
|
||||
* @param time The amount of remaining time the prisoner has
|
||||
* @param jailer The name of the person who jailed this prisoner
|
||||
* @param reason The reason why this prisoner is in jail
|
||||
*/
|
||||
public Prisoner(String uuid, String name, boolean muted, long time, String jailer, String reason) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.muted = muted;
|
||||
this.time = time;
|
||||
this.jailer = jailer;
|
||||
this.reason = reason;
|
||||
this.offlinePending = false;
|
||||
this.teleporting = false;
|
||||
this.toBeTransferred = false;
|
||||
this.previousPosition = null;
|
||||
this.previousGameMode = GameMode.SURVIVAL;
|
||||
this.inventory = "";
|
||||
this.armor = "";
|
||||
this.afk = 0;
|
||||
}
|
||||
|
||||
/** Returns the UUID of the prisoner. */
|
||||
public UUID getUUID() {
|
||||
return UUID.fromString(this.uuid);
|
||||
}
|
||||
|
||||
/** Gets the name of this prisoner. */
|
||||
public String getLastKnownName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Sets the name of this prisoner. */
|
||||
public String setLastKnownName(String username) {
|
||||
this.name = username;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/** Gets the reason this player was jailed for. */
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
/** Sets the reason this player was jailed for. */
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/** Gets the person who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.jailer;
|
||||
}
|
||||
|
||||
/** Sets the person who jailed this prisoner. */
|
||||
public void setJailer(String jailer) {
|
||||
this.jailer = jailer;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner is muted or not. */
|
||||
public boolean isMuted() {
|
||||
return this.muted;
|
||||
}
|
||||
|
||||
/** Sets whether the prisoner is muted or not. */
|
||||
public void setMuted(boolean muted) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prisoner has. */
|
||||
public long getRemainingTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prisoner has in minutes. */
|
||||
public long getRemainingTimeInMinutes() {
|
||||
return TimeUnit.MINUTES.convert(time, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/** Gets the remaining time the prison has in minutes except only in int format. */
|
||||
public int getRemainingTimeInMinutesInt() {
|
||||
return (int) this.getRemainingTimeInMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the remaining time the prisoner has left.
|
||||
*
|
||||
* @param time The amount of time left, in milliseconds.
|
||||
*/
|
||||
public void setRemainingTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given time to the remaining time the prisoner has left.
|
||||
*
|
||||
* @param time to add to the prisoner's remaining time.
|
||||
* @return the new remaining time the prisoner has
|
||||
*/
|
||||
public long addTime(long time) {
|
||||
this.time += time;
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts the given time from the remaining time the prisoner has left.
|
||||
*
|
||||
* @param time to subtract from the prisoner's remaining time.
|
||||
* @return the new remaining time the prisoner has
|
||||
*/
|
||||
public long subtractTime(long time) {
|
||||
this.time -= time;
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/** Gets whether the player is offline or not. */
|
||||
public boolean isOfflinePending() {
|
||||
return this.offlinePending;
|
||||
}
|
||||
|
||||
/** Sets whether the player is offline or not. */
|
||||
public void setOfflinePending(boolean offline) {
|
||||
this.offlinePending = offline;
|
||||
}
|
||||
|
||||
/** Gets whether the player is being teleported or not. */
|
||||
public boolean isTeleporting() {
|
||||
return this.teleporting;
|
||||
}
|
||||
|
||||
/** Sets whether the player is being teleported or not. */
|
||||
public void setTeleporting(boolean teleport) {
|
||||
this.teleporting = teleport;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
||||
public boolean isToBeTransferred() {
|
||||
return this.toBeTransferred;
|
||||
}
|
||||
|
||||
/** Sets whether the prisoner is going to be transferred or not, mainly for teleporting on join purposes. */
|
||||
public void setToBeTransferred(boolean transferred) {
|
||||
this.toBeTransferred = transferred;
|
||||
}
|
||||
|
||||
/** Gets the previous location of this player, can be null. */
|
||||
public Location getPreviousLocation() {
|
||||
return this.previousPosition;
|
||||
}
|
||||
|
||||
/** Gets the previous location of this player, separated by a comma. */
|
||||
public String getPreviousLocationString() {
|
||||
if(previousPosition == null) return "";
|
||||
else return previousPosition.getWorld().getName() + "," +
|
||||
previousPosition.getX() + "," +
|
||||
previousPosition.getY() + "," +
|
||||
previousPosition.getZ() + "," +
|
||||
previousPosition.getYaw() + "," +
|
||||
previousPosition.getPitch();
|
||||
}
|
||||
|
||||
/** Sets the previous location of this player. */
|
||||
public void setPreviousPosition(Location location) {
|
||||
this.previousPosition = location;
|
||||
}
|
||||
|
||||
/** Sets the previous location of this player from a comma separated string. */
|
||||
public void setPreviousPosition(String location) {
|
||||
if(location == null) return;
|
||||
if(location.isEmpty()) return;
|
||||
|
||||
String[] s = location.split(",");
|
||||
this.previousPosition = new Location(Bukkit.getWorld(s[0]),
|
||||
Double.valueOf(s[1]),
|
||||
Double.valueOf(s[2]),
|
||||
Double.valueOf(s[3]),
|
||||
Float.valueOf(s[4]),
|
||||
Float.valueOf(s[5]));
|
||||
}
|
||||
|
||||
/** Gets the previous gamemode of this player. */
|
||||
public GameMode getPreviousGameMode() {
|
||||
return this.previousGameMode;
|
||||
}
|
||||
|
||||
/** Sets the previous gamemode of this player. */
|
||||
public void setPreviousGameMode(GameMode previous) {
|
||||
this.previousGameMode = previous;
|
||||
}
|
||||
|
||||
/** Sets the previous gamemode of this player based upon the provided string. */
|
||||
public void setPreviousGameMode(String previous) {
|
||||
if(previous == null) return;
|
||||
else if(previous.isEmpty()) return;
|
||||
else this.previousGameMode = GameMode.valueOf(previous);
|
||||
}
|
||||
|
||||
/** Gets the inventory string for this player, it is encoded in Base64 string. */
|
||||
public String getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
/** Sets the inventory Base64 string. */
|
||||
public void setInventory(String inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
/** Gets the armor content, encoded in Base64 string. */
|
||||
public String getArmor() {
|
||||
return this.armor;
|
||||
}
|
||||
|
||||
/** Sets the armor inventory Base64 string. */
|
||||
public void setArmor(String armor) {
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
/** Gets the time, in milliseconds, this prisoner has been afk. */
|
||||
public long getAFKTime() {
|
||||
return this.afk;
|
||||
}
|
||||
|
||||
/** Sets the time, in milliseconds, this prisoner has been afk. */
|
||||
public void setAFKTime(long time) {
|
||||
this.afk = time;
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +1,103 @@
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* Simple location class which doesn't store any instances of {@link World worlds} or {@link org.bukkit.block.Block blocks}, just uses strings, floats, and doubles.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.1.1
|
||||
*/
|
||||
public class SimpleLocation {
|
||||
private String world;
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleLocation with each detail provided separately.
|
||||
*
|
||||
* @param world as a string
|
||||
* @param x coordinate as a double
|
||||
* @param y coordinate as a double
|
||||
* @param z coordinate as a double
|
||||
* @param yaw as a float
|
||||
* @param pitch as a float
|
||||
*/
|
||||
public SimpleLocation(String world, double x, double y, double z, float yaw, float pitch) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SimpleLocation with all the detail provided from {@link Location}.
|
||||
*
|
||||
* @param location to convert to a SimpleLocation
|
||||
*/
|
||||
public SimpleLocation(Location location) {
|
||||
this.world = location.getWorld().getName();
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.yaw = location.getYaw();
|
||||
this.pitch = location.getPitch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Simple Location with all the inputs being in string.
|
||||
*
|
||||
* @param world the name of the world
|
||||
* @param x coordinate as a string
|
||||
* @param y coordinate as a string
|
||||
* @param z coordinate as a string
|
||||
*/
|
||||
public SimpleLocation(String world, String x, String y, String z) {
|
||||
this.world = world;
|
||||
this.x = Double.valueOf(x);
|
||||
this.y = Double.valueOf(y);
|
||||
this.z = Double.valueOf(z);
|
||||
this.yaw = 0;
|
||||
this.pitch = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SimpleLocation with each detail provided separately.
|
||||
*
|
||||
* @param world as a string
|
||||
* @param x coordinate as a double
|
||||
* @param y coordinate as a double
|
||||
* @param z coordinate as a double
|
||||
*/
|
||||
public SimpleLocation(String world, double x, double y, double z) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/** Returns the instance from Bukkit of the world this location is in. */
|
||||
public World getWorld() {
|
||||
return Bukkit.getWorld(world);
|
||||
}
|
||||
|
||||
/** Returns the name of the world this location is in. */
|
||||
public String getWorldName() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/** Returns a new {@link Location} from this SimpleLocation. */
|
||||
public Location getLocation() {
|
||||
return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return world + "," + x + "," + y + "," + z + "," + yaw + "," + pitch;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* Simple location class which doesn't store any instances of {@link World worlds} or {@link org.bukkit.block.Block blocks}, just uses strings, floats, and doubles.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.1.1
|
||||
*/
|
||||
public class SimpleLocation {
|
||||
private String world;
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleLocation with each detail provided separately.
|
||||
*
|
||||
* @param world as a string
|
||||
* @param x coordinate as a double
|
||||
* @param y coordinate as a double
|
||||
* @param z coordinate as a double
|
||||
* @param yaw as a float
|
||||
* @param pitch as a float
|
||||
*/
|
||||
public SimpleLocation(String world, double x, double y, double z, float yaw, float pitch) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SimpleLocation with all the detail provided from {@link Location}.
|
||||
*
|
||||
* @param location to convert to a SimpleLocation
|
||||
*/
|
||||
public SimpleLocation(Location location) {
|
||||
this.world = location.getWorld().getName();
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.yaw = location.getYaw();
|
||||
this.pitch = location.getPitch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Simple Location with all the inputs being in string.
|
||||
*
|
||||
* @param world the name of the world
|
||||
* @param x coordinate as a string
|
||||
* @param y coordinate as a string
|
||||
* @param z coordinate as a string
|
||||
*/
|
||||
public SimpleLocation(String world, String x, String y, String z) {
|
||||
this.world = world;
|
||||
this.x = Double.valueOf(x);
|
||||
this.y = Double.valueOf(y);
|
||||
this.z = Double.valueOf(z);
|
||||
this.yaw = 0;
|
||||
this.pitch = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SimpleLocation with each detail provided separately.
|
||||
*
|
||||
* @param world as a string
|
||||
* @param x coordinate as a double
|
||||
* @param y coordinate as a double
|
||||
* @param z coordinate as a double
|
||||
*/
|
||||
public SimpleLocation(String world, double x, double y, double z) {
|
||||
this.world = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/** Returns the instance from Bukkit of the world this location is in. */
|
||||
public World getWorld() {
|
||||
return Bukkit.getWorld(world);
|
||||
}
|
||||
|
||||
/** Returns the name of the world this location is in. */
|
||||
public String getWorldName() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/** Returns a new {@link Location} from this SimpleLocation. */
|
||||
public Location getLocation() {
|
||||
return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return world + "," + x + "," + y + "," + z + "," + yaw + "," + pitch;
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,37 @@
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
/**
|
||||
* Represents a Jail Stick, contains all the information.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 1.0.1
|
||||
* @since 3.0.0
|
||||
*
|
||||
*/
|
||||
public class Stick {
|
||||
private String jail, reason;
|
||||
private long time;
|
||||
|
||||
public Stick(String jail, String reason, long time) {
|
||||
this.jail = jail;
|
||||
this.reason = reason;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return time + "," + jail + "," + reason;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.beans;
|
||||
|
||||
/**
|
||||
* Represents a Jail Stick, contains all the information.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @version 1.0.1
|
||||
* @since 3.0.0
|
||||
*
|
||||
*/
|
||||
public class Stick {
|
||||
private String jail, reason;
|
||||
private long time;
|
||||
|
||||
public Stick(String jail, String reason, long time) {
|
||||
this.jail = jail;
|
||||
this.reason = reason;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return time + "," + jail + "," + reason;
|
||||
}
|
||||
}
|
||||
|
@ -1,173 +1,173 @@
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.commands.HandCuffCommand;
|
||||
import com.graywolf336.jail.command.commands.ToggleJailDebugCommand;
|
||||
import com.graywolf336.jail.command.commands.UnHandCuffCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailForceCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailCommand;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
/**
|
||||
* Where all the commands are registered at and handled, processed, at.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.2
|
||||
*
|
||||
*/
|
||||
public class CommandHandler {
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public CommandHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " commands.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If the command is registered or not.</li>
|
||||
* <li>If more than one command matches the command's name and sends the usage for each one.</li>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param commandLine The name of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public void handleCommand(JailManager jailmanager, CommandSender sender, String commandLine, String[] args) {
|
||||
List<Command> matches = getMatches(commandLine);
|
||||
|
||||
//If no matches were found, send them the unknown command message.
|
||||
if(matches.size() == 0) {
|
||||
if(commandLine.startsWith("jail")) {
|
||||
String j = commandLine.substring(0, 4);
|
||||
String a0 = commandLine.substring(4, commandLine.length());
|
||||
|
||||
ArrayList<String> args2 = new ArrayList<String>();
|
||||
for(String s : args)
|
||||
args2.add(s);
|
||||
args2.add(a0);
|
||||
|
||||
if(jailmanager.getPlugin().onCommand(sender, null, j, args2.toArray(new String[args2.size()])))
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.UNKNOWNCOMMAND, commandLine));
|
||||
return;
|
||||
}
|
||||
|
||||
//If more than one command was found, send them each command's help message.
|
||||
if(matches.size() > 1) {
|
||||
for(Command c : matches)
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
Command c = matches.get(0);
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
return;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
if(args.length < i.minimumArgs()) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
/** Loads all the commands into the hashmap. */
|
||||
private void loadCommands() {
|
||||
load(HandCuffCommand.class);
|
||||
load(ToggleJailDebugCommand.class);
|
||||
load(UnHandCuffCommand.class);
|
||||
load(UnJailCommand.class);
|
||||
load(UnJailForceCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.commands.HandCuffCommand;
|
||||
import com.graywolf336.jail.command.commands.ToggleJailDebugCommand;
|
||||
import com.graywolf336.jail.command.commands.UnHandCuffCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailForceCommand;
|
||||
import com.graywolf336.jail.command.commands.UnJailCommand;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
/**
|
||||
* Where all the commands are registered at and handled, processed, at.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.2
|
||||
*
|
||||
*/
|
||||
public class CommandHandler {
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public CommandHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " commands.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If the command is registered or not.</li>
|
||||
* <li>If more than one command matches the command's name and sends the usage for each one.</li>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param commandLine The name of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public void handleCommand(JailManager jailmanager, CommandSender sender, String commandLine, String[] args) {
|
||||
List<Command> matches = getMatches(commandLine);
|
||||
|
||||
//If no matches were found, send them the unknown command message.
|
||||
if(matches.size() == 0) {
|
||||
if(commandLine.startsWith("jail")) {
|
||||
String j = commandLine.substring(0, 4);
|
||||
String a0 = commandLine.substring(4, commandLine.length());
|
||||
|
||||
ArrayList<String> args2 = new ArrayList<String>();
|
||||
for(String s : args)
|
||||
args2.add(s);
|
||||
args2.add(a0);
|
||||
|
||||
if(jailmanager.getPlugin().onCommand(sender, null, j, args2.toArray(new String[args2.size()])))
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.UNKNOWNCOMMAND, commandLine));
|
||||
return;
|
||||
}
|
||||
|
||||
//If more than one command was found, send them each command's help message.
|
||||
if(matches.size() > 1) {
|
||||
for(Command c : matches)
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
Command c = matches.get(0);
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
return;
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
return;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
if(args.length < i.minimumArgs()) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
/** Loads all the commands into the hashmap. */
|
||||
private void loadCommands() {
|
||||
load(HandCuffCommand.class);
|
||||
load(ToggleJailDebugCommand.class);
|
||||
load(UnHandCuffCommand.class);
|
||||
load(UnJailCommand.class);
|
||||
load(UnJailForceCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,212 +1,212 @@
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.subcommands.JailCellCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCheckCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearForceCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailConfirmCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailPayCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailRecordCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailReloadCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStatusCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStopCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTimeCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferAllCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailVersionCommand;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
public class JailHandler {
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public JailHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " sub-commands of /jail.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public boolean parseCommand(JailManager jailmanager, CommandSender sender, String[] args) {
|
||||
Command c = null;
|
||||
|
||||
//If they didn't provide any arguments (aka just: /jail) then we will need to send them some help
|
||||
if(args.length == 0) {
|
||||
//TODO: Create the help page(s)
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
}else {
|
||||
//Get the matches from the first argument passed
|
||||
List<Command> matches = getMatches(args[0]);
|
||||
|
||||
if(matches.size() == 0) {
|
||||
//No matches found, thus it is more likely than not they are trying to jail someone
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
} else if(matches.size() > 1) {
|
||||
//If there was found more than one match
|
||||
//then let's send the usage of each match to the sender
|
||||
for(Command cmd : matches)
|
||||
showUsage(sender, cmd);
|
||||
return true;
|
||||
|
||||
}else {
|
||||
//Only one match was found, so let's continue
|
||||
c = matches.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!i.permission().isEmpty()) {
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
jailmanager.getPlugin().debug("Sender has no permission.");
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
jailmanager.getPlugin().debug("Sender is not a player.");
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(args.length - 1 < i.minimumArgs()) {
|
||||
jailmanager.getPlugin().debug("Sender didn't provide enough arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length - 1) {
|
||||
jailmanager.getPlugin().debug("Sender provided too many arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if(jailmanager.getPlugin().inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
private void loadCommands() {
|
||||
load(JailCellCreateCommand.class);
|
||||
load(JailCheckCommand.class);
|
||||
load(JailClearCommand.class);
|
||||
load(JailClearForceCommand.class);
|
||||
load(JailCommand.class);
|
||||
load(JailConfirmCommand.class);
|
||||
load(JailCreateCommand.class);
|
||||
load(JailDeleteCellCommand.class);
|
||||
load(JailDeleteCellsCommand.class);
|
||||
load(JailDeleteCommand.class);
|
||||
load(JailListCellsCommand.class);
|
||||
load(JailListCommand.class);
|
||||
load(JailMuteCommand.class);
|
||||
load(JailPayCommand.class);
|
||||
load(JailRecordCommand.class);
|
||||
load(JailReloadCommand.class);
|
||||
load(JailStatusCommand.class);
|
||||
load(JailStopCommand.class);
|
||||
load(JailTeleInCommand.class);
|
||||
load(JailTeleOutCommand.class);
|
||||
load(JailTimeCommand.class);
|
||||
load(JailTransferAllCommand.class);
|
||||
load(JailTransferCommand.class);
|
||||
load(JailVersionCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.subcommands.JailCellCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCheckCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailClearForceCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailConfirmCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailCreateCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailDeleteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCellsCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailListCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailMuteCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailPayCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailRecordCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailReloadCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStatusCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailStopCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleInCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTeleOutCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTimeCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferAllCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailTransferCommand;
|
||||
import com.graywolf336.jail.command.subcommands.JailVersionCommand;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
public class JailHandler {
|
||||
private LinkedHashMap<String, Command> commands;
|
||||
|
||||
public JailHandler(JailMain plugin) {
|
||||
commands = new LinkedHashMap<String, Command>();
|
||||
loadCommands();
|
||||
|
||||
plugin.debug("Loaded " + commands.size() + " sub-commands of /jail.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given command and checks that the command is in valid form.
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* It checks in the following order:
|
||||
* <ol>
|
||||
* <li>If they have permission for it, if they don't then we send them a message stating so.</li>
|
||||
* <li>If the command needs a player instance, if so we send a message stating that.</li>
|
||||
* <li>If the required minimum arguments have been passed, if not sends the usage.</li>
|
||||
* <li>If the required maximum arguments have been passed (if there is a max, -1 if no max), if not sends the usage.</li>
|
||||
* <li>Then executes, upon failed execution it sends the usage command.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param jailmanager The instance of {@link JailManager}.
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments passed to the command.
|
||||
*/
|
||||
public boolean parseCommand(JailManager jailmanager, CommandSender sender, String[] args) {
|
||||
Command c = null;
|
||||
|
||||
//If they didn't provide any arguments (aka just: /jail) then we will need to send them some help
|
||||
if(args.length == 0) {
|
||||
//TODO: Create the help page(s)
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
}else {
|
||||
//Get the matches from the first argument passed
|
||||
List<Command> matches = getMatches(args[0]);
|
||||
|
||||
if(matches.size() == 0) {
|
||||
//No matches found, thus it is more likely than not they are trying to jail someone
|
||||
c = getMatches("jail").get(0);
|
||||
|
||||
} else if(matches.size() > 1) {
|
||||
//If there was found more than one match
|
||||
//then let's send the usage of each match to the sender
|
||||
for(Command cmd : matches)
|
||||
showUsage(sender, cmd);
|
||||
return true;
|
||||
|
||||
}else {
|
||||
//Only one match was found, so let's continue
|
||||
c = matches.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
|
||||
|
||||
// First, let's check if the sender has permission for the command.
|
||||
if(!i.permission().isEmpty()) {
|
||||
if(!sender.hasPermission(i.permission())) {
|
||||
jailmanager.getPlugin().debug("Sender has no permission.");
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.NOPERMISSION));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Next, let's check if we need a player and then if the sender is actually a player
|
||||
if(i.needsPlayer() && !(sender instanceof Player)) {
|
||||
jailmanager.getPlugin().debug("Sender is not a player.");
|
||||
sender.sendMessage(jailmanager.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now, let's check the size of the arguments passed. If it is shorter than the minimum required args, let's show the usage.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(args.length - 1 < i.minimumArgs()) {
|
||||
jailmanager.getPlugin().debug("Sender didn't provide enough arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Then, if the maximumArgs doesn't equal -1, we need to check if the size of the arguments passed is greater than the maximum args.
|
||||
// The reason we are subtracting one is because the command is now `/jail <subcommand>` and the subcommand is viewed as an argument
|
||||
if(i.maxArgs() != -1 && i.maxArgs() < args.length - 1) {
|
||||
jailmanager.getPlugin().debug("Sender provided too many arguments.");
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Since everything has been checked and we're all clear, let's execute it.
|
||||
// But if get back false, let's show the usage message.
|
||||
try {
|
||||
if(!c.execute(jailmanager, sender, args)) {
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if(jailmanager.getPlugin().inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
jailmanager.getPlugin().getLogger().severe("An error occured while handling the command: " + i.usage());
|
||||
showUsage(sender, c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Command> getMatches(String command) {
|
||||
List<Command> result = new ArrayList<Command>();
|
||||
|
||||
for(Entry<String, Command> entry : commands.entrySet()) {
|
||||
if(command.matches(entry.getKey())) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the usage information to the sender, if they have permission.
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param command The command to send usage of.
|
||||
*/
|
||||
private void showUsage(CommandSender sender, Command command) {
|
||||
CommandInfo info = command.getClass().getAnnotation(CommandInfo.class);
|
||||
if(!sender.hasPermission(info.permission())) return;
|
||||
|
||||
sender.sendMessage(info.usage());
|
||||
}
|
||||
|
||||
private void loadCommands() {
|
||||
load(JailCellCreateCommand.class);
|
||||
load(JailCheckCommand.class);
|
||||
load(JailClearCommand.class);
|
||||
load(JailClearForceCommand.class);
|
||||
load(JailCommand.class);
|
||||
load(JailConfirmCommand.class);
|
||||
load(JailCreateCommand.class);
|
||||
load(JailDeleteCellCommand.class);
|
||||
load(JailDeleteCellsCommand.class);
|
||||
load(JailDeleteCommand.class);
|
||||
load(JailListCellsCommand.class);
|
||||
load(JailListCommand.class);
|
||||
load(JailMuteCommand.class);
|
||||
load(JailPayCommand.class);
|
||||
load(JailRecordCommand.class);
|
||||
load(JailReloadCommand.class);
|
||||
load(JailStatusCommand.class);
|
||||
load(JailStopCommand.class);
|
||||
load(JailTeleInCommand.class);
|
||||
load(JailTeleOutCommand.class);
|
||||
load(JailTimeCommand.class);
|
||||
load(JailTransferAllCommand.class);
|
||||
load(JailTransferCommand.class);
|
||||
load(JailVersionCommand.class);
|
||||
}
|
||||
|
||||
private void load(Class<? extends Command> c) {
|
||||
CommandInfo info = c.getAnnotation(CommandInfo.class);
|
||||
if(info == null) return;
|
||||
|
||||
try {
|
||||
commands.put(info.pattern(), c.newInstance());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,41 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "handcuff|hc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/handcuff [player]"
|
||||
)
|
||||
public class HandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayer(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(player.hasPermission("jail.cantbehandcuffed")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() }));
|
||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() }));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() }));
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "handcuff|hc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/handcuff [player]"
|
||||
)
|
||||
public class HandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayer(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(player.hasPermission("jail.cantbehandcuffed")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEHANDCUFFED, new String[] { player.getName() }));
|
||||
}else if(jm.isPlayerJailed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CURRENTLYJAILEDHANDCUFF, new String[] { player.getName() }));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
jm.getPlugin().getHandCuffManager().addHandCuffs(player.getUniqueId(), player.getLocation());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSON, new String[] { player.getName() }));
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "togglejaildebug|tjd",
|
||||
permission = "jail.command.toggledebug",
|
||||
usage = "/togglejaildebug"
|
||||
)
|
||||
public class ToggleJailDebugCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean debug = jm.getPlugin().setDebugging(!jm.getPlugin().inDebug());
|
||||
sender.sendMessage("Jail debugging is now: " + (debug ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "togglejaildebug|tjd",
|
||||
permission = "jail.command.toggledebug",
|
||||
usage = "/togglejaildebug"
|
||||
)
|
||||
public class ToggleJailDebugCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
boolean debug = jm.getPlugin().setDebugging(!jm.getPlugin().inDebug());
|
||||
sender.sendMessage("Jail debugging is now: " + (debug ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unhandcuff|uhc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/unhandcuff [player]"
|
||||
)
|
||||
public class UnHandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayerExact(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unhandcuff|uhc",
|
||||
permission = "jail.command.handcuff",
|
||||
usage = "/unhandcuff [player]"
|
||||
)
|
||||
public class UnHandCuffCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = jm.getPlugin().getServer().getPlayerExact(args[0]);
|
||||
|
||||
if(player == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE));
|
||||
}else if(jm.getPlugin().getHandCuffManager().isHandCuffed(player.getUniqueId())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.HANDCUFFSRELEASED, new String[] { player.getName() }));
|
||||
jm.getPlugin().getHandCuffManager().removeHandCuffs(player.getUniqueId());
|
||||
player.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.UNHANDCUFFED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTHANDCUFFED, new String[] { player.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +1,64 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjail|uj",
|
||||
permission = "jail.command.unjail",
|
||||
usage = "/unjail [player]"
|
||||
)
|
||||
public class UnJailCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
Jail j = jm.getJailPlayerIsInByLastKnownName(args[0]);
|
||||
Prisoner pris = j.getPrisonerByLastKnownName(args[0]);
|
||||
Player p = jm.getPlugin().getServer().getPlayer(pris.getUUID());
|
||||
|
||||
//Check if the player is on the server or not
|
||||
if(p == null) {
|
||||
//Check if the player has offline pending and their remaining time is above 0, if so then
|
||||
//forceably unjail them
|
||||
if(pris.isOfflinePending() && pris.getRemainingTime() != 0L) {
|
||||
jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
}else {
|
||||
//The player is not, so we'll set the remaining time to zero and do it when they login next
|
||||
pris.setRemainingTime(0L);
|
||||
pris.setOfflinePending(true);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0]));
|
||||
}
|
||||
}else {
|
||||
//Player is online, so let's try unjailing them
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjail|uj",
|
||||
permission = "jail.command.unjail",
|
||||
usage = "/unjail [player]"
|
||||
)
|
||||
public class UnJailCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
Jail j = jm.getJailPlayerIsInByLastKnownName(args[0]);
|
||||
Prisoner pris = j.getPrisonerByLastKnownName(args[0]);
|
||||
Player p = jm.getPlugin().getServer().getPlayer(pris.getUUID());
|
||||
|
||||
//Check if the player is on the server or not
|
||||
if(p == null) {
|
||||
//Check if the player has offline pending and their remaining time is above 0, if so then
|
||||
//forceably unjail them
|
||||
if(pris.isOfflinePending() && pris.getRemainingTime() != 0L) {
|
||||
jm.getPlugin().getPrisonerManager().forceUnJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
}else {
|
||||
//The player is not, so we'll set the remaining time to zero and do it when they login next
|
||||
pris.setRemainingTime(0L);
|
||||
pris.setOfflinePending(true);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.WILLBEUNJAILED, args[0]));
|
||||
}
|
||||
}else {
|
||||
//Player is online, so let's try unjailing them
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().unJail(j, j.getCellPrisonerIsIn(pris.getUUID()), p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjailforce|ujf",
|
||||
permission = "jail.command.unjailforce",
|
||||
usage = "/unjailforce [player]"
|
||||
)
|
||||
public class UnJailForceCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisonerByLastKnownName(args[0]));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "unjailforce|ujf",
|
||||
permission = "jail.command.unjailforce",
|
||||
usage = "/unjailforce [player]"
|
||||
)
|
||||
public class UnJailForceCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
//Check if the player is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[0])) {
|
||||
jm.getPlugin().getPrisonerManager().forceRelease(jm.getPrisonerByLastKnownName(args[0]));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.FORCEUNJAILED, args[0]));
|
||||
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.LOGJAILINGTOCONSOLE.getPath())) {
|
||||
jm.getPlugin().getLogger().info(ChatColor.stripColor(jm.getPlugin().getJailIO().getLanguageString(LangString.BROADCASTUNJAILING, new String[] { args[0], sender.getName() })));
|
||||
}
|
||||
}else {
|
||||
//The player is not currently jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
package com.graywolf336.jail.command.commands.jewels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.lexicalscope.jewel.cli.Option;
|
||||
|
||||
public interface Jailing {
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"time", "length"}, shortName="t", description = "the amount of time")
|
||||
public String getTime();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
@Option(longName={"muted", "canttalk"}, shortName="m", description = "whether the prisoner is muted or not")
|
||||
public boolean getMuted();
|
||||
|
||||
@Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed")
|
||||
public List<String> getReason();
|
||||
|
||||
public boolean isTime();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
public boolean isMuted();
|
||||
public boolean isReason();
|
||||
}
|
||||
package com.graywolf336.jail.command.commands.jewels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.lexicalscope.jewel.cli.Option;
|
||||
|
||||
public interface Jailing {
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"time", "length"}, shortName="t", description = "the amount of time")
|
||||
public String getTime();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
@Option(longName={"muted", "canttalk"}, shortName="m", description = "whether the prisoner is muted or not")
|
||||
public boolean getMuted();
|
||||
|
||||
@Option(longName={"reason"}, shortName="r", description = "the reason this player is being jailed")
|
||||
public List<String> getReason();
|
||||
|
||||
public boolean isTime();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
public boolean isMuted();
|
||||
public boolean isReason();
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
package com.graywolf336.jail.command.commands.jewels;
|
||||
|
||||
import com.lexicalscope.jewel.cli.Option;
|
||||
|
||||
public interface Transfer {
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
public boolean isPlayer();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
}
|
||||
package com.graywolf336.jail.command.commands.jewels;
|
||||
|
||||
import com.lexicalscope.jewel.cli.Option;
|
||||
|
||||
public interface Transfer {
|
||||
|
||||
@Option(longName={"player", "pl"}, shortName="p", description = "the player's name")
|
||||
public String getPlayer();
|
||||
|
||||
@Option(longName={"jail", "prison"}, shortName="j", description = "the jail")
|
||||
public String getJail();
|
||||
|
||||
@Option(longName={"cell"}, shortName="c", description = "the cell")
|
||||
public String getCell();
|
||||
|
||||
public boolean isPlayer();
|
||||
public boolean isJail();
|
||||
public boolean isCell();
|
||||
}
|
||||
|
@ -1,66 +1,66 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "createcell|cc",
|
||||
permission = "jail.command.jailcreatecells",
|
||||
usage = "/jail cellcreate [jail] (cellname)"
|
||||
)
|
||||
public class JailCellCreateCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName();
|
||||
String jail = args[1].toLowerCase();
|
||||
String cell = "";
|
||||
|
||||
//Only get the cell name they provide if they provide it
|
||||
if(args.length >= 3) {
|
||||
cell = args[2];
|
||||
}
|
||||
|
||||
//Check if the player is currently creating something else
|
||||
if(jm.isCreatingSomething(name)) {
|
||||
String message = jm.getStepMessage(name);
|
||||
if(!message.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "You're already creating something else, please finish it or cancel.");
|
||||
}
|
||||
}else {
|
||||
//Not creating anything, so let them create some cells.
|
||||
if(jm.isValidJail(jail)) {
|
||||
Jail j = jm.getJail(jail);
|
||||
|
||||
//If they didn't provide a cell name, let's provide one ourself.
|
||||
if(cell.isEmpty()) cell = "cell_n" + (j.getCellCount() + 1);
|
||||
|
||||
if(j.getCell(cell) == null) {
|
||||
if(jm.addCreatingCell(name, jail, cell)) {
|
||||
jm.getCellCreationSteps().startStepping(player);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "Appears you're creating a cell or something went wrong on our side.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "There's already a cell with the name '" + cell + "', please pick a new one or remove that cell.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "No such jail found by the name of '" + jail + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = true,
|
||||
pattern = "createcell|cc",
|
||||
permission = "jail.command.jailcreatecells",
|
||||
usage = "/jail cellcreate [jail] (cellname)"
|
||||
)
|
||||
public class JailCellCreateCommand implements Command {
|
||||
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
String name = player.getName();
|
||||
String jail = args[1].toLowerCase();
|
||||
String cell = "";
|
||||
|
||||
//Only get the cell name they provide if they provide it
|
||||
if(args.length >= 3) {
|
||||
cell = args[2];
|
||||
}
|
||||
|
||||
//Check if the player is currently creating something else
|
||||
if(jm.isCreatingSomething(name)) {
|
||||
String message = jm.getStepMessage(name);
|
||||
if(!message.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + message);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "You're already creating something else, please finish it or cancel.");
|
||||
}
|
||||
}else {
|
||||
//Not creating anything, so let them create some cells.
|
||||
if(jm.isValidJail(jail)) {
|
||||
Jail j = jm.getJail(jail);
|
||||
|
||||
//If they didn't provide a cell name, let's provide one ourself.
|
||||
if(cell.isEmpty()) cell = "cell_n" + (j.getCellCount() + 1);
|
||||
|
||||
if(j.getCell(cell) == null) {
|
||||
if(jm.addCreatingCell(name, jail, cell)) {
|
||||
jm.getCellCreationSteps().startStepping(player);
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "Appears you're creating a cell or something went wrong on our side.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "There's already a cell with the name '" + cell + "', please pick a new one or remove that cell.");
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "No such jail found by the name of '" + jail + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,217 +1,217 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Jailing;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = -1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "jail|j",
|
||||
permission = "jail.command.jail",
|
||||
usage = "/jail [name] (-t time) (-j JailName) (-c CellName) (-m Muted) (-r A reason for jailing)"
|
||||
)
|
||||
public class JailCommand implements Command {
|
||||
|
||||
/*
|
||||
* Executes the command. Checks the following:
|
||||
*
|
||||
* - If there are any jails.
|
||||
* - If the command can be parsed correctly.
|
||||
* - If the player is already jailed.
|
||||
* - If the given time can be parsed correctly, defaults to what is defined in the config
|
||||
* - If the jail is reasonable or not, else sets the one from the config
|
||||
* - If the cell is not empty then checks to be sure that cell exists
|
||||
* - If the prisoner is online or not.
|
||||
*/
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
return true;
|
||||
}
|
||||
|
||||
//This is just to add the -p param so CliFactory doesn't blow up
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//Only add the "-p" if it doesn't already contain it, this way people can do `/jail -p check` in the event someone
|
||||
//has a name which is one of our subcommands
|
||||
if(!arguments.contains("-p")) arguments.add(0, "-p");
|
||||
|
||||
Jailing params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Jailing.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check if they've actually given us a player to jail
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.JAILING));
|
||||
return true;
|
||||
}else {
|
||||
jm.getPlugin().debug("We are getting ready to handle jailing: " + params.getPlayer());
|
||||
}
|
||||
|
||||
//Check if the given player is already jailed or not
|
||||
if(jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Try to parse the time, if they give us nothing in the time parameter then we get the default time
|
||||
//from the config and if that isn't there then we default to thirty minutes.
|
||||
Long time = 10L;
|
||||
try {
|
||||
if(params.getTime() == null) {
|
||||
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
|
||||
}else if(params.getTime() == String.valueOf(-1)) {
|
||||
time = -1L;
|
||||
}else {
|
||||
time = Util.getTime(params.getTime());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NUMBERFORMATINCORRECT));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check the jail params. If it is empty, let's get the default jail
|
||||
//from the config. If that is nearest, let's make a call to getting the nearest jail to
|
||||
//the sender but otherwise if it isn't nearest then let's set it to the default jail
|
||||
//which is defined in the config.
|
||||
String jailName = "";
|
||||
if(params.getJail() == null) {
|
||||
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
|
||||
if(dJail.equalsIgnoreCase("nearest")) {
|
||||
jailName = jm.getNearestJail(sender).getName();
|
||||
}else {
|
||||
jailName = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
}
|
||||
}else if(jm.getJail(params.getJail()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}else {
|
||||
jailName = params.getJail();
|
||||
}
|
||||
|
||||
//Check if the cell is defined, and if so check to be sure it exists.
|
||||
if(params.getCell() != null) {
|
||||
if(jm.getJail(params.getJail()).getCell(params.getCell()) == null) {
|
||||
//There is no cell by that name
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else if(jm.getJail(params.getJail()).getCell(params.getCell()).hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
Cell suggestedCell = jm.getJail(params.getJail()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getJail(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getJail()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the jailer gave no reason, then let's get the default reason
|
||||
String reason = "";
|
||||
if(params.getReason() == null) {
|
||||
reason = jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON);
|
||||
}else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String s : params.getReason()) {
|
||||
sb.append(s).append(' ');
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
reason = sb.toString();
|
||||
}
|
||||
|
||||
//If the config has automatic muting, then let's set them as muted
|
||||
boolean muted = params.getMuted();
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) {
|
||||
muted = true;
|
||||
}
|
||||
|
||||
Player p = jm.getPlugin().getServer().getPlayer(params.getPlayer());
|
||||
|
||||
//If the player instance is not null and the player has the permission
|
||||
//'jail.cantbejailed' then don't allow this to happen
|
||||
if(p != null && p.hasPermission("jail.cantbejailed")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEJAILED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String uuid = "";
|
||||
if(p == null) {
|
||||
//TODO: Make this whole jail command non-blocking
|
||||
uuid = jm.getPlugin().getServer().getOfflinePlayer(params.getPlayer()).getUniqueId().toString();
|
||||
}else {
|
||||
uuid = p.getUniqueId().toString();
|
||||
}
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
Jail j = jm.getJail(jailName);
|
||||
Cell c = j.getCell(params.getCell());
|
||||
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
|
||||
|
||||
//call the event
|
||||
PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
//check if the event is cancelled
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty())
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, params.getPlayer()));
|
||||
else
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//recall data from the event
|
||||
j = event.getJail();
|
||||
c = event.getCell();
|
||||
pris = event.getPrisoner();
|
||||
p = event.getPlayer();
|
||||
|
||||
//Player is not online
|
||||
if(p == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}
|
||||
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Jailing;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = -1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "jail|j",
|
||||
permission = "jail.command.jail",
|
||||
usage = "/jail [name] (-t time) (-j JailName) (-c CellName) (-m Muted) (-r A reason for jailing)"
|
||||
)
|
||||
public class JailCommand implements Command {
|
||||
|
||||
/*
|
||||
* Executes the command. Checks the following:
|
||||
*
|
||||
* - If there are any jails.
|
||||
* - If the command can be parsed correctly.
|
||||
* - If the player is already jailed.
|
||||
* - If the given time can be parsed correctly, defaults to what is defined in the config
|
||||
* - If the jail is reasonable or not, else sets the one from the config
|
||||
* - If the cell is not empty then checks to be sure that cell exists
|
||||
* - If the prisoner is online or not.
|
||||
*/
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
return true;
|
||||
}
|
||||
|
||||
//This is just to add the -p param so CliFactory doesn't blow up
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//Only add the "-p" if it doesn't already contain it, this way people can do `/jail -p check` in the event someone
|
||||
//has a name which is one of our subcommands
|
||||
if(!arguments.contains("-p")) arguments.add(0, "-p");
|
||||
|
||||
Jailing params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Jailing.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check if they've actually given us a player to jail
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.JAILING));
|
||||
return true;
|
||||
}else {
|
||||
jm.getPlugin().debug("We are getting ready to handle jailing: " + params.getPlayer());
|
||||
}
|
||||
|
||||
//Check if the given player is already jailed or not
|
||||
if(jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADYJAILED, params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Try to parse the time, if they give us nothing in the time parameter then we get the default time
|
||||
//from the config and if that isn't there then we default to thirty minutes.
|
||||
Long time = 10L;
|
||||
try {
|
||||
if(params.getTime() == null) {
|
||||
time = Util.getTime(jm.getPlugin().getConfig().getString(Settings.JAILDEFAULTTIME.getPath(), "30m"));
|
||||
}else if(params.getTime() == String.valueOf(-1)) {
|
||||
time = -1L;
|
||||
}else {
|
||||
time = Util.getTime(params.getTime());
|
||||
}
|
||||
}catch(Exception e) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NUMBERFORMATINCORRECT));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check the jail params. If it is empty, let's get the default jail
|
||||
//from the config. If that is nearest, let's make a call to getting the nearest jail to
|
||||
//the sender but otherwise if it isn't nearest then let's set it to the default jail
|
||||
//which is defined in the config.
|
||||
String jailName = "";
|
||||
if(params.getJail() == null) {
|
||||
String dJail = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
|
||||
if(dJail.equalsIgnoreCase("nearest")) {
|
||||
jailName = jm.getNearestJail(sender).getName();
|
||||
}else {
|
||||
jailName = jm.getPlugin().getConfig().getString(Settings.DEFAULTJAIL.getPath());
|
||||
}
|
||||
}else if(jm.getJail(params.getJail()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}else {
|
||||
jailName = params.getJail();
|
||||
}
|
||||
|
||||
//Check if the cell is defined, and if so check to be sure it exists.
|
||||
if(params.getCell() != null) {
|
||||
if(jm.getJail(params.getJail()).getCell(params.getCell()) == null) {
|
||||
//There is no cell by that name
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else if(jm.getJail(params.getJail()).getCell(params.getCell()).hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
Cell suggestedCell = jm.getJail(params.getJail()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getJail(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getJail()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//If the jailer gave no reason, then let's get the default reason
|
||||
String reason = "";
|
||||
if(params.getReason() == null) {
|
||||
reason = jm.getPlugin().getJailIO().getLanguageString(LangString.DEFAULTJAILEDREASON);
|
||||
}else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String s : params.getReason()) {
|
||||
sb.append(s).append(' ');
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
reason = sb.toString();
|
||||
}
|
||||
|
||||
//If the config has automatic muting, then let's set them as muted
|
||||
boolean muted = params.getMuted();
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath())) {
|
||||
muted = true;
|
||||
}
|
||||
|
||||
Player p = jm.getPlugin().getServer().getPlayer(params.getPlayer());
|
||||
|
||||
//If the player instance is not null and the player has the permission
|
||||
//'jail.cantbejailed' then don't allow this to happen
|
||||
if(p != null && p.hasPermission("jail.cantbejailed")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANTBEJAILED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String uuid = "";
|
||||
if(p == null) {
|
||||
//TODO: Make this whole jail command non-blocking
|
||||
uuid = jm.getPlugin().getServer().getOfflinePlayer(params.getPlayer()).getUniqueId().toString();
|
||||
}else {
|
||||
uuid = p.getUniqueId().toString();
|
||||
}
|
||||
|
||||
//Get the jail instance from the name of jail in the params.
|
||||
Jail j = jm.getJail(jailName);
|
||||
Cell c = j.getCell(params.getCell());
|
||||
Prisoner pris = new Prisoner(uuid, params.getPlayer(), muted, time, sender.getName(), reason);
|
||||
|
||||
//call the event
|
||||
PrePrisonerJailedEvent event = new PrePrisonerJailedEvent(j, c, pris, p, p == null, pris.getJailer());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
//check if the event is cancelled
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty())
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, params.getPlayer()));
|
||||
else
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//recall data from the event
|
||||
j = event.getJail();
|
||||
c = event.getCell();
|
||||
pris = event.getPrisoner();
|
||||
p = event.getPlayer();
|
||||
|
||||
//Player is not online
|
||||
if(p == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.OFFLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ONLINEJAIL, new String[] { pris.getLastKnownName(), String.valueOf(pris.getRemainingTimeInMinutes()) }));
|
||||
}
|
||||
|
||||
try {
|
||||
jm.getPlugin().getPrisonerManager().prepareJail(j, c, p, pris);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecell|dc",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecell <jail> <cell>"
|
||||
)
|
||||
public class JailDeleteCellCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecell|dc",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecell <jail> <cell>"
|
||||
)
|
||||
public class JailDeleteCellCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELL));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecells|dcs",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecells <jail>"
|
||||
)
|
||||
public class JailDeleteCellsCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "deletecells|dcs",
|
||||
permission = "jail.command.jaildeletecell",
|
||||
usage = "/jail deletecells <jail>"
|
||||
)
|
||||
public class JailDeleteCellsCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETECELLS));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "delete|d",
|
||||
permission = "jail.command.jaildelete",
|
||||
usage = "/jail delete <jail>"
|
||||
)
|
||||
public class JailDeleteCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.ConfirmPlayer;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.Confirmation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "delete|d",
|
||||
permission = "jail.command.jaildelete",
|
||||
usage = "/jail delete <jail>"
|
||||
)
|
||||
public class JailDeleteCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isConfirming(sender.getName())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.ALREADY));
|
||||
}else {
|
||||
jm.addConfirming(sender.getName(), new ConfirmPlayer(sender.getName(), args, Confirmation.DELETE));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.START));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "listcells|lc",
|
||||
permission = "jail.command.jaillistcell",
|
||||
usage = "/jail listcells <jail>"
|
||||
)
|
||||
public class JailListCellsCommand implements Command {
|
||||
@Override
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------Cells----------");
|
||||
|
||||
if(!jm.getJails().isEmpty()) {
|
||||
if(jm.getJail(args[1]) != null) {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
String message = "";
|
||||
for(Cell c : j.getCells()) {
|
||||
if(message.isEmpty()) {
|
||||
message = c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}else {
|
||||
message += ", " + c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
if(message.isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, j.getName()));
|
||||
}else {
|
||||
sender.sendMessage(ChatColor.GREEN + message);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "listcells|lc",
|
||||
permission = "jail.command.jaillistcell",
|
||||
usage = "/jail listcells <jail>"
|
||||
)
|
||||
public class JailListCellsCommand implements Command {
|
||||
@Override
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------Cells----------");
|
||||
|
||||
if(!jm.getJails().isEmpty()) {
|
||||
if(jm.getJail(args[1]) != null) {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
String message = "";
|
||||
for(Cell c : j.getCells()) {
|
||||
if(message.isEmpty()) {
|
||||
message = c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}else {
|
||||
message += ", " + c.getName() + (c.getPrisoner() == null ? "" : " (" + c.getPrisoner().getLastKnownName() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
if(message.isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELLS, j.getName()));
|
||||
}else {
|
||||
sender.sendMessage(ChatColor.GREEN + message);
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,63 +1,63 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "list|l",
|
||||
permission = "jail.command.jaillist",
|
||||
usage = "/jail list <jail>"
|
||||
)
|
||||
public class JailListCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------" + (args.length == 1 ? "Jails" : "Prisoners") + "----------");
|
||||
|
||||
//Check if there are any jails
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}else {
|
||||
//Check if they have provided a jail to list or not
|
||||
if(args.length == 1) {
|
||||
//No jail provided, so give them a list of the jails
|
||||
for(Jail j : jm.getJails()) {
|
||||
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
if(j == null) {
|
||||
//No jail was found
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
Collection<Prisoner> pris = j.getAllPrisoners().values();
|
||||
|
||||
if(pris.isEmpty()) {
|
||||
//If there are no prisoners, then send that message
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOPRISONERS, j.getName()));
|
||||
}else {
|
||||
for(Prisoner p : pris) {
|
||||
//graywolf663: Being gray's evil twin; CONSOLE (10)
|
||||
//prisoner: reason; jailer (time in minutes)
|
||||
sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "list|l",
|
||||
permission = "jail.command.jaillist",
|
||||
usage = "/jail list <jail>"
|
||||
)
|
||||
public class JailListCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
sender.sendMessage(ChatColor.AQUA + "----------" + (args.length == 1 ? "Jails" : "Prisoners") + "----------");
|
||||
|
||||
//Check if there are any jails
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
}else {
|
||||
//Check if they have provided a jail to list or not
|
||||
if(args.length == 1) {
|
||||
//No jail provided, so give them a list of the jails
|
||||
for(Jail j : jm.getJails()) {
|
||||
sender.sendMessage(ChatColor.BLUE + " " + j.getName() + " (" + j.getAllPrisoners().size() + ")");
|
||||
}
|
||||
}else {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
if(j == null) {
|
||||
//No jail was found
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
Collection<Prisoner> pris = j.getAllPrisoners().values();
|
||||
|
||||
if(pris.isEmpty()) {
|
||||
//If there are no prisoners, then send that message
|
||||
sender.sendMessage(" " + jm.getPlugin().getJailIO().getLanguageString(LangString.NOPRISONERS, j.getName()));
|
||||
}else {
|
||||
for(Prisoner p : pris) {
|
||||
//graywolf663: Being gray's evil twin; CONSOLE (10)
|
||||
//prisoner: reason; jailer (time in minutes)
|
||||
sender.sendMessage(ChatColor.BLUE + " " + p.getLastKnownName() + ": " + p.getReason() + "; " + p.getJailer() + " (" + p.getRemainingTimeInMinutes() + " mins)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "-------------------------");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,38 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "mute|m",
|
||||
permission = "jail.command.jailmute",
|
||||
usage = "/jail mute <player>"
|
||||
)
|
||||
public class JailMuteCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
//Let's check if the player they're sending us is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[1])) {
|
||||
//They are, so let's toggle whether they are muted or not
|
||||
boolean muted = !jm.getPrisonerByLastKnownName(args[1]).isMuted();
|
||||
jm.getPrisonerByLastKnownName(args[1]).setMuted(muted);
|
||||
|
||||
//Send the message to the sender based upon whether they are muted or unmuted
|
||||
if(muted)
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWMUTED, args[1]));
|
||||
else
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWUNMUTED, args[1]));
|
||||
}else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 1,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "mute|m",
|
||||
permission = "jail.command.jailmute",
|
||||
usage = "/jail mute <player>"
|
||||
)
|
||||
public class JailMuteCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
//Let's check if the player they're sending us is jailed
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[1])) {
|
||||
//They are, so let's toggle whether they are muted or not
|
||||
boolean muted = !jm.getPrisonerByLastKnownName(args[1]).isMuted();
|
||||
jm.getPrisonerByLastKnownName(args[1]).setMuted(muted);
|
||||
|
||||
//Send the message to the sender based upon whether they are muted or unmuted
|
||||
if(muted)
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWMUTED, args[1]));
|
||||
else
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOWUNMUTED, args[1]));
|
||||
}else {
|
||||
//The player provided is not jailed, so let's tell the sender that
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[1]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,229 +1,229 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.JailPayManager;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "pay",
|
||||
permission = "jail.usercmd.jailpay",
|
||||
usage = "/jail pay <amount> <player>"
|
||||
)
|
||||
public class JailPayCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
||||
JailPayManager pm = jm.getPlugin().getJailPayManager();
|
||||
|
||||
switch(args.length) {
|
||||
case 1:
|
||||
// `/jail pay`
|
||||
//send how much it costs to get out
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
String amt = "";
|
||||
|
||||
if(pm.usingItemsForPayment()) {
|
||||
amt = String.valueOf((int) Math.ceil(pm.calculateBill(p)));
|
||||
}else {
|
||||
amt = String.valueOf(pm.calculateBill(p));
|
||||
}
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { pm.getCostPerMinute(), pm.getCurrencyName(), amt }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'timed' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}else {
|
||||
if(pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { amt, pm.getCurrencyName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'infinite' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
// `/jail pay <amount>`
|
||||
//They are trying to pay for their self
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIME,
|
||||
new String[] { String.valueOf(amt), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// `/jail pay <amount> <person>
|
||||
//they are trying to pay for someone else
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
//When they are jailed they can not pay for someone else
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCANTPAYWHILEJAILED));
|
||||
}else {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIMEELSE,
|
||||
new String[] { String.valueOf(amt), p.getLastKnownName(), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Person they're trying to pay for is not jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
jm.getPlugin().debug("Jail pay not enabled.");
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
Messages:
|
||||
MessageJailPayAmountForever: To get out of this mess, you will have to pay <Amount>.
|
||||
JailPayCannotPay: Sorry, money won't help you this time.
|
||||
JailPayCannotPayHim: Sorry, money won't help him this time.
|
||||
JailPayNotEnoughMoney: You don't have that much money!
|
||||
JailPayCost: 1 minute of your sentence will cost you <MinutePrice>. That means that cost for releasing you out of the jail is <WholePrice>.
|
||||
JailPayPaidReleased: You have just payed <Amount> and saved yourself from the jail!
|
||||
JailPayPaidReleasedHim: You have just payed <Amount> and saved <Prisoner> from the jail!
|
||||
JailPayLoweredTime: You have just payed <Amount> and lowered your sentence to <NewTime> minutes!
|
||||
JailPayLoweredTimeHim: You have just payed <Amount> and lowered <Prisoner>'s sentence to <NewTime> minutes!
|
||||
JailPay:
|
||||
PricePerMinute: 10
|
||||
PriceForInfiniteJail: 9999
|
||||
Currency: 0
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.JailPayManager;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "pay",
|
||||
permission = "jail.usercmd.jailpay",
|
||||
usage = "/jail pay <amount> <player>"
|
||||
)
|
||||
public class JailPayCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILPAYENABLED.getPath())) {
|
||||
JailPayManager pm = jm.getPlugin().getJailPayManager();
|
||||
|
||||
switch(args.length) {
|
||||
case 1:
|
||||
// `/jail pay`
|
||||
//send how much it costs to get out
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
String amt = "";
|
||||
|
||||
if(pm.usingItemsForPayment()) {
|
||||
amt = String.valueOf((int) Math.ceil(pm.calculateBill(p)));
|
||||
}else {
|
||||
amt = String.valueOf(pm.calculateBill(p));
|
||||
}
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { pm.getCostPerMinute(), pm.getCurrencyName(), amt }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'timed' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}else {
|
||||
if(pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCOST, new String[] { amt, pm.getCurrencyName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
jm.getPlugin().debug("Jail pay 'infinite' paying is not enabled (config has 0 as the cost).");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
// `/jail pay <amount>`
|
||||
//They are trying to pay for their self
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(sender.getName());
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIME,
|
||||
new String[] { String.valueOf(amt), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASED, String.valueOf(bill)));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner((Player) sender, p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.YOUARENOTJAILED));
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// `/jail pay <amount> <person>
|
||||
//they are trying to pay for someone else
|
||||
if(jm.isPlayerJailedByLastKnownUsername(sender.getName())) {
|
||||
//When they are jailed they can not pay for someone else
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYCANTPAYWHILEJAILED));
|
||||
}else {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
if(!pm.isTimedEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}else {
|
||||
if(!pm.isInfiniteEnabled()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(args[1].startsWith("-")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNONEGATIVEAMOUNTS));
|
||||
}else {
|
||||
double amt = 0;
|
||||
|
||||
try {
|
||||
amt = Double.parseDouble(args[1]);
|
||||
}catch(NumberFormatException e) {
|
||||
sender.sendMessage(ChatColor.RED + "<amount> must be a number.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
if(pm.hasEnoughToPay((Player) sender, amt)) {
|
||||
double bill = pm.calculateBill(p);
|
||||
|
||||
if(p.getRemainingTime() > 0) {
|
||||
//timed sentence
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
long minutes = pm.getMinutesPayingFor(amt);
|
||||
pm.pay((Player) sender, amt);
|
||||
long remain = p.subtractTime(TimeUnit.MILLISECONDS.convert(minutes, TimeUnit.MINUTES));
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDLOWEREDTIMEELSE,
|
||||
new String[] { String.valueOf(amt), p.getLastKnownName(), String.valueOf(TimeUnit.MINUTES.convert(remain, TimeUnit.MILLISECONDS)) }));
|
||||
}
|
||||
}else {
|
||||
//infinite jailing
|
||||
if(amt >= bill) {
|
||||
pm.pay((Player) sender, bill);
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYPAIDRELEASEDELSE, new String[] { String.valueOf(bill), p.getLastKnownName() }));
|
||||
jm.getPlugin().getPrisonerManager().releasePrisoner(jm.getPlugin().getServer().getPlayer(p.getUUID()), p);
|
||||
}else {
|
||||
//You haven't provided enough money to get them out
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEYPROVIDED));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENOUGHMONEY));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Person they're trying to pay for is not jailed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
jm.getPlugin().debug("Jail pay not enabled.");
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PAYNOTENABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
Messages:
|
||||
MessageJailPayAmountForever: To get out of this mess, you will have to pay <Amount>.
|
||||
JailPayCannotPay: Sorry, money won't help you this time.
|
||||
JailPayCannotPayHim: Sorry, money won't help him this time.
|
||||
JailPayNotEnoughMoney: You don't have that much money!
|
||||
JailPayCost: 1 minute of your sentence will cost you <MinutePrice>. That means that cost for releasing you out of the jail is <WholePrice>.
|
||||
JailPayPaidReleased: You have just payed <Amount> and saved yourself from the jail!
|
||||
JailPayPaidReleasedHim: You have just payed <Amount> and saved <Prisoner> from the jail!
|
||||
JailPayLoweredTime: You have just payed <Amount> and lowered your sentence to <NewTime> minutes!
|
||||
JailPayLoweredTimeHim: You have just payed <Amount> and lowered <Prisoner>'s sentence to <NewTime> minutes!
|
||||
JailPay:
|
||||
PricePerMinute: 10
|
||||
PriceForInfiniteJail: 9999
|
||||
Currency: 0
|
||||
*/
|
@ -1,45 +1,45 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
permission = "jail.command.jailrecord",
|
||||
usage = "/jail record <username> <display>"
|
||||
)
|
||||
public class JailRecordCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
if(args.length == 2) {
|
||||
// /jail record <username>
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else if(args.length == 3) {
|
||||
// /jail record <username> something
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
//Send all the record entries
|
||||
for(String s : entries) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else {
|
||||
//They didn't do the command right
|
||||
//send them back to get the usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
permission = "jail.command.jailrecord",
|
||||
usage = "/jail record <username> <display>"
|
||||
)
|
||||
public class JailRecordCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
if(args.length == 2) {
|
||||
// /jail record <username>
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else if(args.length == 3) {
|
||||
// /jail record <username> something
|
||||
List<String> entries = jm.getPlugin().getJailIO().getRecordEntries(args[1]);
|
||||
|
||||
//Send all the record entries
|
||||
for(String s : entries) {
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.RECORDTIMESJAILED, new String[] { args[1], String.valueOf(entries.size()) }));
|
||||
}else {
|
||||
//They didn't do the command right
|
||||
//send them back to get the usage
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
permission = "jail.command.jailreload",
|
||||
usage = "/jail reload"
|
||||
)
|
||||
public class JailReloadCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
try {
|
||||
jm.getPlugin().reloadConfig();
|
||||
jm.getPlugin().getJailIO().loadLanguage();
|
||||
jm.getPlugin().getJailIO().loadJails();
|
||||
jm.getPlugin().reloadScoreBoardManager();
|
||||
jm.getPlugin().reloadJailSticks();
|
||||
jm.getPlugin().reloadJailPayManager();
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLUGINRELOADED));
|
||||
}catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = false,
|
||||
pattern = "reload|r",
|
||||
permission = "jail.command.jailreload",
|
||||
usage = "/jail reload"
|
||||
)
|
||||
public class JailReloadCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||
try {
|
||||
jm.getPlugin().reloadConfig();
|
||||
jm.getPlugin().getJailIO().loadLanguage();
|
||||
jm.getPlugin().getJailIO().loadJails();
|
||||
jm.getPlugin().reloadScoreBoardManager();
|
||||
jm.getPlugin().reloadJailSticks();
|
||||
jm.getPlugin().reloadJailPayManager();
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLUGINRELOADED));
|
||||
}catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "stick",
|
||||
permission = "jail.usercmd.jailstick",
|
||||
usage = "/jail stick"
|
||||
)
|
||||
public class JailStickCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
|
||||
boolean using = jm.getPlugin().getJailStickManager().toggleUsingStick(sender.getName());
|
||||
|
||||
if(using) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKENABLED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKDISABLED));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKUSAGEDISABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 0,
|
||||
minimumArgs = 0,
|
||||
needsPlayer = true,
|
||||
pattern = "stick",
|
||||
permission = "jail.usercmd.jailstick",
|
||||
usage = "/jail stick"
|
||||
)
|
||||
public class JailStickCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getPlugin().getConfig().getBoolean(Settings.JAILSTICKENABLED.getPath())) {
|
||||
boolean using = jm.getPlugin().getJailStickManager().toggleUsingStick(sender.getName());
|
||||
|
||||
if(using) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKENABLED));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKDISABLED));
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.JAILSTICKUSAGEDISABLED));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "telein|teleportin",
|
||||
permission = "jail.command.jailtelein",
|
||||
usage = "/jail telein <jailname> (player)"
|
||||
)
|
||||
public class JailTeleInCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "telein|teleportin",
|
||||
permission = "jail.command.jailtelein",
|
||||
usage = "/jail telein <jailname> (player)"
|
||||
)
|
||||
public class JailTeleInCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportIn());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEIN, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,54 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "teleout|teleportout",
|
||||
permission = "jail.command.jailteleout",
|
||||
usage = "/jail teleout <jailname> (player)"
|
||||
)
|
||||
public class JailTeleOutCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 1,
|
||||
needsPlayer = false,
|
||||
pattern = "teleout|teleportout",
|
||||
permission = "jail.command.jailteleout",
|
||||
usage = "/jail teleout <jailname> (player)"
|
||||
)
|
||||
public class JailTeleOutCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
Jail j = jm.getJail(args[1]);
|
||||
|
||||
//The jail doesn't exist
|
||||
if(j == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
}else {
|
||||
//The jail does exist
|
||||
//now let's check the size of the command
|
||||
//if it has two args then someone is sending someone else in
|
||||
//otherwise it is just the sender going in
|
||||
if(args.length == 3) {
|
||||
Player p = jm.getPlugin().getServer().getPlayer(args[2]);
|
||||
|
||||
//If the player they're trying to send is offline, don't do anything
|
||||
if(p == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERNOTONLINE, args[2]));
|
||||
}else {
|
||||
p.teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { args[2], args[1] }));
|
||||
}
|
||||
}else {
|
||||
if(sender instanceof Player) {
|
||||
((Player) sender).teleport(j.getTeleportFree());
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TELEOUT, new String[] { sender.getName(), args[1] }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PLAYERCONTEXTREQUIRED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,55 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 3,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "time|t",
|
||||
permission = "jail.command.jailtime",
|
||||
usage = "/jail time <add|remove|show> <player> <time>"
|
||||
)
|
||||
public class JailTimeCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
switch(args.length) {
|
||||
case 3:
|
||||
if(args[1].equalsIgnoreCase("show")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
p.addTime(Util.getTime(args[3]));
|
||||
}else if(args[1].equalsIgnoreCase("remove")) {
|
||||
p.subtractTime(Util.getTime(args[3]));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 3,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "time|t",
|
||||
permission = "jail.command.jailtime",
|
||||
usage = "/jail time <add|remove|show> <player> <time>"
|
||||
)
|
||||
public class JailTimeCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.isPlayerJailedByLastKnownUsername(args[2])) {
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(args[2]);
|
||||
|
||||
switch(args.length) {
|
||||
case 3:
|
||||
if(args[1].equalsIgnoreCase("show")) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(args[1].equalsIgnoreCase("add")) {
|
||||
p.addTime(Util.getTime(args[3]));
|
||||
}else if(args[1].equalsIgnoreCase("remove")) {
|
||||
p.subtractTime(Util.getTime(args[3]));
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PRISONERSTIME,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, args[2]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,56 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transferall|transall",
|
||||
permission = "jail.command.jailtransferall",
|
||||
usage = "/jail transferall oldjail targetjail"
|
||||
)
|
||||
public class JailTransferAllCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Starting to transfer everyone from '" + args[1] + "' into '" + args[2] + "'.");
|
||||
|
||||
//Check if the oldjail is not a valid jail
|
||||
if(!jm.isValidJail(args[1])) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
return true;
|
||||
}else if(!jm.isValidJail(args[2])) {
|
||||
//Check if the targetjail is a valid jail as well
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[2]));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Sending the transferring off, jail checks all came clean.");
|
||||
|
||||
Jail old = jm.getJail(args[1]);
|
||||
HashSet<Prisoner> oldPrisoners = new HashSet<Prisoner>(old.getAllPrisoners().values());
|
||||
|
||||
//Transfer all the prisoners
|
||||
for(Prisoner p : oldPrisoners) {
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(old, old.getCellPrisonerIsIn(p.getUUID()), jm.getJail(args[2]), null, p);
|
||||
}
|
||||
|
||||
//Send the messages to the sender when completed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERALLCOMPLETE, new String[] { old.getName(), args[2] }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 2,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transferall|transall",
|
||||
permission = "jail.command.jailtransferall",
|
||||
usage = "/jail transferall oldjail targetjail"
|
||||
)
|
||||
public class JailTransferAllCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Starting to transfer everyone from '" + args[1] + "' into '" + args[2] + "'.");
|
||||
|
||||
//Check if the oldjail is not a valid jail
|
||||
if(!jm.isValidJail(args[1])) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[1]));
|
||||
return true;
|
||||
}else if(!jm.isValidJail(args[2])) {
|
||||
//Check if the targetjail is a valid jail as well
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, args[2]));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Sending the transferring off, jail checks all came clean.");
|
||||
|
||||
Jail old = jm.getJail(args[1]);
|
||||
HashSet<Prisoner> oldPrisoners = new HashSet<Prisoner>(old.getAllPrisoners().values());
|
||||
|
||||
//Transfer all the prisoners
|
||||
for(Prisoner p : oldPrisoners) {
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(old, old.getCellPrisonerIsIn(p.getUUID()), jm.getJail(args[2]), null, p);
|
||||
}
|
||||
|
||||
//Send the messages to the sender when completed
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERALLCOMPLETE, new String[] { old.getName(), args[2] }));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,139 +1,139 @@
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
|
||||
import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 6,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transfer|trans",
|
||||
permission = "jail.command.jailtransfer",
|
||||
usage = "/jail transfer -p player -j jail -c cell"
|
||||
)
|
||||
public class JailTransferCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Convert to a List<String> so we can edit the list
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//remove the first argument of "transfer"
|
||||
arguments.remove(0);
|
||||
|
||||
//Parse the command
|
||||
Transfer params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Transfer.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Verify they gave us a player and if so check if they're jailed
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer());
|
||||
|
||||
//If they didn't provide a jail, tell them we need one
|
||||
if(params.getJail() == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else {
|
||||
//Check if the jail they did provided is not a valid jail
|
||||
if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("They provided a valid jail, so let's check the target cell.");
|
||||
|
||||
Jail target = jm.getJail(params.getJail());
|
||||
Cell targetCell = null;
|
||||
|
||||
//Check if they provided a cell and if so does it exist
|
||||
if(params.getCell() != null) {
|
||||
if(target.getCell(params.getCell()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else {
|
||||
//Store the cell for easy of access and also check if it already is full
|
||||
targetCell = target.getCell(params.getCell());
|
||||
if(targetCell.hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getCell()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Calling the PrePrisonerTransferredEvent, jail and cell check all came out clean.");
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(params.getPlayer());
|
||||
|
||||
//Throw the custom event before transferring them, allowing another plugin to cancel it.
|
||||
PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p, jm.getPlugin().getServer().getPlayer(p.getUUID()), sender.getName());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty()) {
|
||||
//The plugin didn't provide a cancel message/reason so send the default one
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCANCELLEDBYANOTHERPLUGIN, params.getPlayer()));
|
||||
}else {
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Start the transferring of the prisoner
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p);
|
||||
|
||||
//Send the messages to the sender, if no cell then say that but if cell send that as well
|
||||
if(targetCell == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETENOCELL, new String[] { params.getPlayer(), target.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETECELL, new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.command.subcommands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.command.Command;
|
||||
import com.graywolf336.jail.command.CommandInfo;
|
||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
|
||||
import com.lexicalscope.jewel.cli.ArgumentValidationException;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
@CommandInfo(
|
||||
maxArgs = 6,
|
||||
minimumArgs = 2,
|
||||
needsPlayer = false,
|
||||
pattern = "transfer|trans",
|
||||
permission = "jail.command.jailtransfer",
|
||||
usage = "/jail transfer -p player -j jail -c cell"
|
||||
)
|
||||
public class JailTransferCommand implements Command {
|
||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||
if(jm.getJails().isEmpty()) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAILS));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Convert to a List<String> so we can edit the list
|
||||
List<String> arguments = new LinkedList<String>(Arrays.asList(args));
|
||||
//remove the first argument of "transfer"
|
||||
arguments.remove(0);
|
||||
|
||||
//Parse the command
|
||||
Transfer params = null;
|
||||
|
||||
try {
|
||||
params = CliFactory.parseArguments(Transfer.class, arguments.toArray(new String[arguments.size()]));
|
||||
}catch(ArgumentValidationException e) {
|
||||
sender.sendMessage(ChatColor.RED + e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
//Verify they gave us a player and if so check if they're jailed
|
||||
if(params.getPlayer() == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAPLAYER, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else if(!jm.isPlayerJailedByLastKnownUsername(params.getPlayer())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOTJAILED, params.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Checking everything before we transfer: " + params.getPlayer());
|
||||
|
||||
//If they didn't provide a jail, tell them we need one
|
||||
if(params.getJail() == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.PROVIDEAJAIL, LangString.TRANSFERRING));
|
||||
return true;
|
||||
}else {
|
||||
//Check if the jail they did provided is not a valid jail
|
||||
if(!jm.isValidJail(params.getJail())) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOJAIL, params.getJail()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("They provided a valid jail, so let's check the target cell.");
|
||||
|
||||
Jail target = jm.getJail(params.getJail());
|
||||
Cell targetCell = null;
|
||||
|
||||
//Check if they provided a cell and if so does it exist
|
||||
if(params.getCell() != null) {
|
||||
if(target.getCell(params.getCell()) == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOCELL, new String[] { params.getCell(), params.getJail() }));
|
||||
return true;
|
||||
}else {
|
||||
//Store the cell for easy of access and also check if it already is full
|
||||
targetCell = target.getCell(params.getCell());
|
||||
if(targetCell.hasPrisoner()) {
|
||||
//If the cell has a prisoner, don't allow jailing them to that particular cell
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.CELLNOTEMPTY, params.getCell()));
|
||||
|
||||
//But suggest the first empty cell we find
|
||||
Cell suggestedCell = jm.getJail(params.getCell()).getFirstEmptyCell();
|
||||
if(suggestedCell != null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.SUGGESTEDCELL, new String[] { params.getCell(), suggestedCell.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.NOEMPTYCELLS, params.getCell()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jm.getPlugin().debug("Calling the PrePrisonerTransferredEvent, jail and cell check all came out clean.");
|
||||
Prisoner p = jm.getPrisonerByLastKnownName(params.getPlayer());
|
||||
|
||||
//Throw the custom event before transferring them, allowing another plugin to cancel it.
|
||||
PrePrisonerTransferredEvent event = new PrePrisonerTransferredEvent(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p, jm.getPlugin().getServer().getPlayer(p.getUUID()), sender.getName());
|
||||
jm.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(event.isCancelled()) {
|
||||
if(event.getCancelledMessage().isEmpty()) {
|
||||
//The plugin didn't provide a cancel message/reason so send the default one
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCANCELLEDBYANOTHERPLUGIN, params.getPlayer()));
|
||||
}else {
|
||||
sender.sendMessage(event.getCancelledMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Start the transferring of the prisoner
|
||||
jm.getPlugin().getPrisonerManager().transferPrisoner(jm.getJailPlayerIsIn(p.getUUID()),
|
||||
jm.getJailPlayerIsIn(p.getUUID()).getCellPrisonerIsIn(p.getUUID()),
|
||||
target, targetCell, p);
|
||||
|
||||
//Send the messages to the sender, if no cell then say that but if cell send that as well
|
||||
if(targetCell == null) {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETENOCELL, new String[] { params.getPlayer(), target.getName() }));
|
||||
}else {
|
||||
sender.sendMessage(jm.getPlugin().getJailIO().getLanguageString(LangString.TRANSFERCOMPLETECELL, new String[] { params.getPlayer(), target.getName(), targetCell.getName() }));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.graywolf336.jail.enums;
|
||||
|
||||
public enum Confirmation {
|
||||
/** When they are clearing a jail from all their prisoner's with releasing properly. */
|
||||
CLEAR,
|
||||
/** When they are clearing a jail from all their prisoner's by force. */
|
||||
CLEARFORCE,
|
||||
/** When they are deleting a cell from a jail. */
|
||||
DELETECELL,
|
||||
/** When they are deleting all a jail's cells. */
|
||||
DELETECELLS,
|
||||
/** When they are deleting a jail. */
|
||||
DELETE;
|
||||
}
|
||||
package com.graywolf336.jail.enums;
|
||||
|
||||
public enum Confirmation {
|
||||
/** When they are clearing a jail from all their prisoner's with releasing properly. */
|
||||
CLEAR,
|
||||
/** When they are clearing a jail from all their prisoner's by force. */
|
||||
CLEARFORCE,
|
||||
/** When they are deleting a cell from a jail. */
|
||||
DELETECELL,
|
||||
/** When they are deleting all a jail's cells. */
|
||||
DELETECELLS,
|
||||
/** When they are deleting a jail. */
|
||||
DELETE;
|
||||
}
|
||||
|
@ -1,221 +1,221 @@
|
||||
package com.graywolf336.jail.enums;
|
||||
|
||||
public enum LangString {
|
||||
//actions section
|
||||
|
||||
/** Section for when they break a block. */
|
||||
BLOCKBREAKING ("actions"),
|
||||
/** Section for when they place a block. */
|
||||
BLOCKPLACING ("actions"),
|
||||
/** Section for when they try to do a command that isn't whitelisted. */
|
||||
COMMAND ("actions"),
|
||||
/** Section for when a player tramples a crop and protection is enabled. */
|
||||
CROPTRAMPLING ("actions"),
|
||||
/** Section for when a player interacts with a block that is blacklisted. */
|
||||
INTERACTIONBLOCKS ("actions"),
|
||||
/** Section for when a player interacts with an item that is blacklisted. */
|
||||
INTERACTIONITEMS ("actions"),
|
||||
/** Section for when a player moves outside of the jail. */
|
||||
MOVING ("actions"),
|
||||
|
||||
//Jailing section
|
||||
|
||||
/** The message displayed when players are kicked for being afk. */
|
||||
AFKKICKMESSAGE ("jailing"),
|
||||
/** The message sent when jailing someone that is already jailed. */
|
||||
ALREADYJAILED ("jailing"),
|
||||
/** The message sent when we broadcast/log the message for time below -1. */
|
||||
BROADCASTMESSAGEFOREVER ("jailing"),
|
||||
/** The message sent when we broadcast/log the message for any time above -1. */
|
||||
BROADCASTMESSAGEFORMINUTES ("jailing"),
|
||||
/** The message sent to the broadcast/log the unjailing of someone. */
|
||||
BROADCASTUNJAILING ("jailing"),
|
||||
/** The message sent to the sender when trying to jail someone and a plugin cancels it but doesn't leave a message why. */
|
||||
CANCELLEDBYANOTHERPLUGIN ("jailing"),
|
||||
/** The message sent when trying to jail someone who can't be jailed by permission. */
|
||||
CANTBEJAILED ("jailing"),
|
||||
/** The message sent to the sender when they are trying to jail into a cell which is not empty. */
|
||||
CELLNOTEMPTY ("jailing"),
|
||||
/** The message sent when someone is jailed without a reason. */
|
||||
DEFAULTJAILEDREASON ("jailing"),
|
||||
/** The message sent when someone is unjailed yet they never came online and so they were forcefully unjailed. */
|
||||
FORCEUNJAILED ("jailing"),
|
||||
/** The message sent when players are jailed without a reason. */
|
||||
JAILED ("jailing"),
|
||||
/** The message sent when players are jailed with a reason. */
|
||||
JAILEDWITHREASON ("jailing"),
|
||||
/** The message sent when players are jailed and they try to talk. */
|
||||
MUTED ("jailing"),
|
||||
/** The message sent when the sender tries to jail someone in a cell and there aren't any cells to suggest. */
|
||||
NOEMPTYCELLS ("jailing"),
|
||||
/** The message sent to the sender when they list all the prisoners in a jail which has no prisoners. */
|
||||
NOPRISONERS ("jailing"),
|
||||
/** The message sent when a player is not jailed and the sender is trying to see/do something about it. */
|
||||
NOTJAILED ("jailing"),
|
||||
/** The message sent to the sender when they mute a prisoner. */
|
||||
NOWMUTED ("jailing"),
|
||||
/** The message sent to the sender when they unmute a prisoner. */
|
||||
NOWUNMUTED ("jailing"),
|
||||
/** The message sent to the jailer when they jail someone offline. */
|
||||
OFFLINEJAIL ("jailing"),
|
||||
/** The message sent to the jailer when they jail someone who is online. */
|
||||
ONLINEJAIL ("jailing"),
|
||||
/** The message sent when finding out how much time a prisoner has. */
|
||||
PRISONERSTIME ("jailing"),
|
||||
/** The message sent to the prisoner when they try to do something but it is protected. */
|
||||
PROTECTIONMESSAGE ("jailing"),
|
||||
/** The message sent to the prisoner when they try to do something and it is protected, but no penalty. */
|
||||
PROTECTIONMESSAGENOPENALTY ("jailing"),
|
||||
/** The message sent to the sender when they need to provide a player. */
|
||||
PROVIDEAPLAYER ("jailing"),
|
||||
/** The message sent to the sender when they need to provide a jail. */
|
||||
PROVIDEAJAIL ("jailing"),
|
||||
/** The message sent when to a prisoner about their status in jail. */
|
||||
STATUS ("jailing"),
|
||||
/** The message sent to the sender of a command when suggesting a cell. */
|
||||
SUGGESTEDCELL ("jailing"),
|
||||
/** The message sent to the sender when they teleport someone to a jail's teleport in location. */
|
||||
TELEIN ("jailing"),
|
||||
/** The message sent to the sender when they teleport someone to a jail's teleport out location. */
|
||||
TELEOUT ("jailing"),
|
||||
/** The message sent to the sender when they transfer all a jail's prisoners to another jail. */
|
||||
TRANSFERALLCOMPLETE ("jailing"),
|
||||
/** The message sent when another plugin cancels the transferring but doesn't provide a reason why. */
|
||||
TRANSFERCANCELLEDBYANOTHERPLUGIN ("jailing"),
|
||||
/** The message sent to the sender when they transfer someone to a jail and a cell. */
|
||||
TRANSFERCOMPLETECELL ("jailing"),
|
||||
/** The message sent to the sender when they transfer someone to a jail. */
|
||||
TRANSFERCOMPLETENOCELL ("jailing"),
|
||||
/** The message sent to the player when they get transferred to a new jail. */
|
||||
TRANSFERRED ("jailing"),
|
||||
/** The message sent when players are released from jail. */
|
||||
UNJAILED ("jailing"),
|
||||
/** The message went when an offline player is unjailed. */
|
||||
WILLBEUNJAILED ("jailing"),
|
||||
/** The message sent to the sender when they check their jail status and they aren't jailed. */
|
||||
YOUARENOTJAILED ("jailing"),
|
||||
|
||||
//Handcuffing section
|
||||
|
||||
/** The message sent to the sender when trying to handcuff someone who can't be. */
|
||||
CANTBEHANDCUFFED ("handcuffing"),
|
||||
/** The message sent to the sender whenever they try to handcuff someone who is in jail. */
|
||||
CURRENTLYJAILEDHANDCUFF ("handcuffing", "currentlyjailed"),
|
||||
/** The message sent to the sender when the player doesn't have any handcuffs. */
|
||||
NOTHANDCUFFED ("handcuffing"),
|
||||
/** The message sent to the handcuff on a successful handcuffing. */
|
||||
HANDCUFFSON ("handcuffing"),
|
||||
/** The message sent when players are handcuffed. */
|
||||
HANDCUFFED ("handcuffing"),
|
||||
/** The message sent to the player who has release handcuffs. */
|
||||
HANDCUFFSRELEASED ("handcuffing"),
|
||||
/** The message sent when the player has his/her handcuffs removed. */
|
||||
UNHANDCUFFED ("handcuffing"),
|
||||
|
||||
//General section, used by different parts
|
||||
|
||||
/** Part message of any messages which require 'all the jails' or such. */
|
||||
ALLJAILS ("general"),
|
||||
/** The message sent to the sender whenever they try to remove a cell but was unsuccessful due to a prisoner. */
|
||||
CELLREMOVALUNSUCCESSFUL ("general"),
|
||||
/** The message sent whenever a cell is successfully removed. */
|
||||
CELLREMOVED ("general"),
|
||||
/** The simple word jailing to be put in other parts. */
|
||||
JAILING ("jailing"),
|
||||
/** THe message sent to the sender when they try to remove a jail but there are still prisoners in there. */
|
||||
JAILREMOVALUNSUCCESSFUL ("general"),
|
||||
/** The message sent whenever a jail is successfully removed. */
|
||||
JAILREMOVED ("general"),
|
||||
/** The message sent whenever a player toggles using jail stick to disabled. */
|
||||
JAILSTICKDISABLED ("general"),
|
||||
/** The message sent whenever a player toggles using jail stick to enabled. */
|
||||
JAILSTICKENABLED ("general"),
|
||||
/** The message sent whenever a player tries to toggle using jail stick but the config has it disabled. */
|
||||
JAILSTICKUSAGEDISABLED ("general"),
|
||||
/** Message sent when doing something that requires a cell but the given name of a cell doesn't exist. */
|
||||
NOCELL ("general"),
|
||||
/** Message sent when needing a cell or something and there are no cells. */
|
||||
NOCELLS ("general"),
|
||||
/** The message sent whenever the sender does something which the jail does not found. */
|
||||
NOJAIL ("general"),
|
||||
/** The message sent whenever the sender does something and there are no jails. */
|
||||
NOJAILS ("general"),
|
||||
/** The message sent whenever the sender/player doesn't have permission. */
|
||||
NOPERMISSION ("general"),
|
||||
/** The message sent whenever the sender/player supplies a number format that is incorrect. */
|
||||
NUMBERFORMATINCORRECT ("general"),
|
||||
/** The message sent whenever something is done that needs a player but doesn't have it. */
|
||||
PLAYERCONTEXTREQUIRED ("general"),
|
||||
/** The message sent whenever an online player is required but not found. */
|
||||
PLAYERNOTONLINE ("general"),
|
||||
/** The message sent to the sender when the plugin data has been reloaded. */
|
||||
PLUGINRELOADED ("general"),
|
||||
/** The message sent whenever the prisoners are cleared from jail(s). */
|
||||
PRISONERSCLEARED ("general"),
|
||||
/** The format we should use when entering a record into flatfile or showing it. */
|
||||
RECORDENTRY ("general"),
|
||||
/** The message format sent saying how many times a user has been jailed.*/
|
||||
RECORDTIMESJAILED ("general"),
|
||||
/** The format of the time entry we should use for the record entries. */
|
||||
TIMEFORMAT ("general"),
|
||||
/** The simple word transferring to be put in other parts. */
|
||||
TRANSFERRING ("general"),
|
||||
/** The message sent whenever someone does a command we don't know. */
|
||||
UNKNOWNCOMMAND ("general"),
|
||||
|
||||
//Jail pay
|
||||
/** The message sent when the jail pay portion is not enabled. */
|
||||
PAYNOTENABLED ("jailpay", "notenabled"),
|
||||
/** The message sent when finding out how much it costs. */
|
||||
PAYCOST ("jailpay", "cost"),
|
||||
/** The message sent when finding out how much it costs and they are jailed forever. */
|
||||
PAYCOSTINFINITE ("jailpay", "costinfinite"),
|
||||
/** The message sent when someone tries to pay a negative amount. */
|
||||
PAYNONEGATIVEAMOUNTS ("jailpay", "nonegativeamounts"),
|
||||
/** The message sent when someone is jailed and tries to pay for someone else. */
|
||||
PAYCANTPAYWHILEJAILED ("jailpay", "cantpayforotherswhilejailed"),
|
||||
/** The message sent whenever someone tries to pay an amount they don't have. */
|
||||
PAYNOTENOUGHMONEY ("jailpay", "notenoughmoney"),
|
||||
/** The message sent when they try to pay an amount but it isn't enough for the jailing sentence. */
|
||||
PAYNOTENOUGHMONEYPROVIDED ("jailpay", "notenoughmoneyprovided"),
|
||||
/** The message sent when they pay and get released. */
|
||||
PAYPAIDRELEASED ("jailpay", "paidreleased"),
|
||||
/** The message sent when they pay for someone else and release them. */
|
||||
PAYPAIDRELEASEDELSE ("jailpay", "PAYPAIDRELEASEDELSE"),
|
||||
/** The message sent when they pay and lower their time. */
|
||||
PAYPAIDLOWEREDTIME ("jailpay", "paidloweredtime"),
|
||||
/** The message sent when they pay and lower someone else's time. */
|
||||
PAYPAIDLOWEREDTIMEELSE ("jailpay", "paidloweredtimeelse"),
|
||||
|
||||
//Confirming action messages.
|
||||
|
||||
/** The message sent when the sender is already confirming something. */
|
||||
ALREADY ("confirm"),
|
||||
/** The message sent when their confirmation has expired. */
|
||||
EXPIRED ("confirm"),
|
||||
/** The message sent to the sender when they tried to confirm something but don't have anything to confirm. */
|
||||
NOTHING ("confirm"),
|
||||
/** The message sent to the sender when they type something and need to confirm it. */
|
||||
START ("confirm");
|
||||
|
||||
private String section, name;
|
||||
|
||||
LangString(String section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
LangString(String section, String name) {
|
||||
this.section = section;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/** Gets the section in the language file this is located at. */
|
||||
public String getSection() {
|
||||
return this.section;
|
||||
}
|
||||
|
||||
/** Returns the name of this enum if a custom one isn't present. */
|
||||
public String getName() {
|
||||
return (name == null ? this.toString().toLowerCase() : name);
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.enums;
|
||||
|
||||
public enum LangString {
|
||||
//actions section
|
||||
|
||||
/** Section for when they break a block. */
|
||||
BLOCKBREAKING ("actions"),
|
||||
/** Section for when they place a block. */
|
||||
BLOCKPLACING ("actions"),
|
||||
/** Section for when they try to do a command that isn't whitelisted. */
|
||||
COMMAND ("actions"),
|
||||
/** Section for when a player tramples a crop and protection is enabled. */
|
||||
CROPTRAMPLING ("actions"),
|
||||
/** Section for when a player interacts with a block that is blacklisted. */
|
||||
INTERACTIONBLOCKS ("actions"),
|
||||
/** Section for when a player interacts with an item that is blacklisted. */
|
||||
INTERACTIONITEMS ("actions"),
|
||||
/** Section for when a player moves outside of the jail. */
|
||||
MOVING ("actions"),
|
||||
|
||||
//Jailing section
|
||||
|
||||
/** The message displayed when players are kicked for being afk. */
|
||||
AFKKICKMESSAGE ("jailing"),
|
||||
/** The message sent when jailing someone that is already jailed. */
|
||||
ALREADYJAILED ("jailing"),
|
||||
/** The message sent when we broadcast/log the message for time below -1. */
|
||||
BROADCASTMESSAGEFOREVER ("jailing"),
|
||||
/** The message sent when we broadcast/log the message for any time above -1. */
|
||||
BROADCASTMESSAGEFORMINUTES ("jailing"),
|
||||
/** The message sent to the broadcast/log the unjailing of someone. */
|
||||
BROADCASTUNJAILING ("jailing"),
|
||||
/** The message sent to the sender when trying to jail someone and a plugin cancels it but doesn't leave a message why. */
|
||||
CANCELLEDBYANOTHERPLUGIN ("jailing"),
|
||||
/** The message sent when trying to jail someone who can't be jailed by permission. */
|
||||
CANTBEJAILED ("jailing"),
|
||||
/** The message sent to the sender when they are trying to jail into a cell which is not empty. */
|
||||
CELLNOTEMPTY ("jailing"),
|
||||
/** The message sent when someone is jailed without a reason. */
|
||||
DEFAULTJAILEDREASON ("jailing"),
|
||||
/** The message sent when someone is unjailed yet they never came online and so they were forcefully unjailed. */
|
||||
FORCEUNJAILED ("jailing"),
|
||||
/** The message sent when players are jailed without a reason. */
|
||||
JAILED ("jailing"),
|
||||
/** The message sent when players are jailed with a reason. */
|
||||
JAILEDWITHREASON ("jailing"),
|
||||
/** The message sent when players are jailed and they try to talk. */
|
||||
MUTED ("jailing"),
|
||||
/** The message sent when the sender tries to jail someone in a cell and there aren't any cells to suggest. */
|
||||
NOEMPTYCELLS ("jailing"),
|
||||
/** The message sent to the sender when they list all the prisoners in a jail which has no prisoners. */
|
||||
NOPRISONERS ("jailing"),
|
||||
/** The message sent when a player is not jailed and the sender is trying to see/do something about it. */
|
||||
NOTJAILED ("jailing"),
|
||||
/** The message sent to the sender when they mute a prisoner. */
|
||||
NOWMUTED ("jailing"),
|
||||
/** The message sent to the sender when they unmute a prisoner. */
|
||||
NOWUNMUTED ("jailing"),
|
||||
/** The message sent to the jailer when they jail someone offline. */
|
||||
OFFLINEJAIL ("jailing"),
|
||||
/** The message sent to the jailer when they jail someone who is online. */
|
||||
ONLINEJAIL ("jailing"),
|
||||
/** The message sent when finding out how much time a prisoner has. */
|
||||
PRISONERSTIME ("jailing"),
|
||||
/** The message sent to the prisoner when they try to do something but it is protected. */
|
||||
PROTECTIONMESSAGE ("jailing"),
|
||||
/** The message sent to the prisoner when they try to do something and it is protected, but no penalty. */
|
||||
PROTECTIONMESSAGENOPENALTY ("jailing"),
|
||||
/** The message sent to the sender when they need to provide a player. */
|
||||
PROVIDEAPLAYER ("jailing"),
|
||||
/** The message sent to the sender when they need to provide a jail. */
|
||||
PROVIDEAJAIL ("jailing"),
|
||||
/** The message sent when to a prisoner about their status in jail. */
|
||||
STATUS ("jailing"),
|
||||
/** The message sent to the sender of a command when suggesting a cell. */
|
||||
SUGGESTEDCELL ("jailing"),
|
||||
/** The message sent to the sender when they teleport someone to a jail's teleport in location. */
|
||||
TELEIN ("jailing"),
|
||||
/** The message sent to the sender when they teleport someone to a jail's teleport out location. */
|
||||
TELEOUT ("jailing"),
|
||||
/** The message sent to the sender when they transfer all a jail's prisoners to another jail. */
|
||||
TRANSFERALLCOMPLETE ("jailing"),
|
||||
/** The message sent when another plugin cancels the transferring but doesn't provide a reason why. */
|
||||
TRANSFERCANCELLEDBYANOTHERPLUGIN ("jailing"),
|
||||
/** The message sent to the sender when they transfer someone to a jail and a cell. */
|
||||
TRANSFERCOMPLETECELL ("jailing"),
|
||||
/** The message sent to the sender when they transfer someone to a jail. */
|
||||
TRANSFERCOMPLETENOCELL ("jailing"),
|
||||
/** The message sent to the player when they get transferred to a new jail. */
|
||||
TRANSFERRED ("jailing"),
|
||||
/** The message sent when players are released from jail. */
|
||||
UNJAILED ("jailing"),
|
||||
/** The message went when an offline player is unjailed. */
|
||||
WILLBEUNJAILED ("jailing"),
|
||||
/** The message sent to the sender when they check their jail status and they aren't jailed. */
|
||||
YOUARENOTJAILED ("jailing"),
|
||||
|
||||
//Handcuffing section
|
||||
|
||||
/** The message sent to the sender when trying to handcuff someone who can't be. */
|
||||
CANTBEHANDCUFFED ("handcuffing"),
|
||||
/** The message sent to the sender whenever they try to handcuff someone who is in jail. */
|
||||
CURRENTLYJAILEDHANDCUFF ("handcuffing", "currentlyjailed"),
|
||||
/** The message sent to the sender when the player doesn't have any handcuffs. */
|
||||
NOTHANDCUFFED ("handcuffing"),
|
||||
/** The message sent to the handcuff on a successful handcuffing. */
|
||||
HANDCUFFSON ("handcuffing"),
|
||||
/** The message sent when players are handcuffed. */
|
||||
HANDCUFFED ("handcuffing"),
|
||||
/** The message sent to the player who has release handcuffs. */
|
||||
HANDCUFFSRELEASED ("handcuffing"),
|
||||
/** The message sent when the player has his/her handcuffs removed. */
|
||||
UNHANDCUFFED ("handcuffing"),
|
||||
|
||||
//General section, used by different parts
|
||||
|
||||
/** Part message of any messages which require 'all the jails' or such. */
|
||||
ALLJAILS ("general"),
|
||||
/** The message sent to the sender whenever they try to remove a cell but was unsuccessful due to a prisoner. */
|
||||
CELLREMOVALUNSUCCESSFUL ("general"),
|
||||
/** The message sent whenever a cell is successfully removed. */
|
||||
CELLREMOVED ("general"),
|
||||
/** The simple word jailing to be put in other parts. */
|
||||
JAILING ("jailing"),
|
||||
/** THe message sent to the sender when they try to remove a jail but there are still prisoners in there. */
|
||||
JAILREMOVALUNSUCCESSFUL ("general"),
|
||||
/** The message sent whenever a jail is successfully removed. */
|
||||
JAILREMOVED ("general"),
|
||||
/** The message sent whenever a player toggles using jail stick to disabled. */
|
||||
JAILSTICKDISABLED ("general"),
|
||||
/** The message sent whenever a player toggles using jail stick to enabled. */
|
||||
JAILSTICKENABLED ("general"),
|
||||
/** The message sent whenever a player tries to toggle using jail stick but the config has it disabled. */
|
||||
JAILSTICKUSAGEDISABLED ("general"),
|
||||
/** Message sent when doing something that requires a cell but the given name of a cell doesn't exist. */
|
||||
NOCELL ("general"),
|
||||
/** Message sent when needing a cell or something and there are no cells. */
|
||||
NOCELLS ("general"),
|
||||
/** The message sent whenever the sender does something which the jail does not found. */
|
||||
NOJAIL ("general"),
|
||||
/** The message sent whenever the sender does something and there are no jails. */
|
||||
NOJAILS ("general"),
|
||||
/** The message sent whenever the sender/player doesn't have permission. */
|
||||
NOPERMISSION ("general"),
|
||||
/** The message sent whenever the sender/player supplies a number format that is incorrect. */
|
||||
NUMBERFORMATINCORRECT ("general"),
|
||||
/** The message sent whenever something is done that needs a player but doesn't have it. */
|
||||
PLAYERCONTEXTREQUIRED ("general"),
|
||||
/** The message sent whenever an online player is required but not found. */
|
||||
PLAYERNOTONLINE ("general"),
|
||||
/** The message sent to the sender when the plugin data has been reloaded. */
|
||||
PLUGINRELOADED ("general"),
|
||||
/** The message sent whenever the prisoners are cleared from jail(s). */
|
||||
PRISONERSCLEARED ("general"),
|
||||
/** The format we should use when entering a record into flatfile or showing it. */
|
||||
RECORDENTRY ("general"),
|
||||
/** The message format sent saying how many times a user has been jailed.*/
|
||||
RECORDTIMESJAILED ("general"),
|
||||
/** The format of the time entry we should use for the record entries. */
|
||||
TIMEFORMAT ("general"),
|
||||
/** The simple word transferring to be put in other parts. */
|
||||
TRANSFERRING ("general"),
|
||||
/** The message sent whenever someone does a command we don't know. */
|
||||
UNKNOWNCOMMAND ("general"),
|
||||
|
||||
//Jail pay
|
||||
/** The message sent when the jail pay portion is not enabled. */
|
||||
PAYNOTENABLED ("jailpay", "notenabled"),
|
||||
/** The message sent when finding out how much it costs. */
|
||||
PAYCOST ("jailpay", "cost"),
|
||||
/** The message sent when finding out how much it costs and they are jailed forever. */
|
||||
PAYCOSTINFINITE ("jailpay", "costinfinite"),
|
||||
/** The message sent when someone tries to pay a negative amount. */
|
||||
PAYNONEGATIVEAMOUNTS ("jailpay", "nonegativeamounts"),
|
||||
/** The message sent when someone is jailed and tries to pay for someone else. */
|
||||
PAYCANTPAYWHILEJAILED ("jailpay", "cantpayforotherswhilejailed"),
|
||||
/** The message sent whenever someone tries to pay an amount they don't have. */
|
||||
PAYNOTENOUGHMONEY ("jailpay", "notenoughmoney"),
|
||||
/** The message sent when they try to pay an amount but it isn't enough for the jailing sentence. */
|
||||
PAYNOTENOUGHMONEYPROVIDED ("jailpay", "notenoughmoneyprovided"),
|
||||
/** The message sent when they pay and get released. */
|
||||
PAYPAIDRELEASED ("jailpay", "paidreleased"),
|
||||
/** The message sent when they pay for someone else and release them. */
|
||||
PAYPAIDRELEASEDELSE ("jailpay", "PAYPAIDRELEASEDELSE"),
|
||||
/** The message sent when they pay and lower their time. */
|
||||
PAYPAIDLOWEREDTIME ("jailpay", "paidloweredtime"),
|
||||
/** The message sent when they pay and lower someone else's time. */
|
||||
PAYPAIDLOWEREDTIMEELSE ("jailpay", "paidloweredtimeelse"),
|
||||
|
||||
//Confirming action messages.
|
||||
|
||||
/** The message sent when the sender is already confirming something. */
|
||||
ALREADY ("confirm"),
|
||||
/** The message sent when their confirmation has expired. */
|
||||
EXPIRED ("confirm"),
|
||||
/** The message sent to the sender when they tried to confirm something but don't have anything to confirm. */
|
||||
NOTHING ("confirm"),
|
||||
/** The message sent to the sender when they type something and need to confirm it. */
|
||||
START ("confirm");
|
||||
|
||||
private String section, name;
|
||||
|
||||
LangString(String section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
LangString(String section, String name) {
|
||||
this.section = section;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/** Gets the section in the language file this is located at. */
|
||||
public String getSection() {
|
||||
return this.section;
|
||||
}
|
||||
|
||||
/** Returns the name of this enum if a custom one isn't present. */
|
||||
public String getName() {
|
||||
return (name == null ? this.toString().toLowerCase() : name);
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +1,70 @@
|
||||
package com.graywolf336.jail.enums;
|
||||
|
||||
public enum Settings {
|
||||
AUTOMATICMUTE("jailing.jail.automaticMute"),
|
||||
BROADCASTJAILING("jailing.jail.broadcastJailing"),
|
||||
BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"),
|
||||
BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"),
|
||||
BLOCKBREAKWHITELIST("jailing.during.blockBreakWhiteList"),
|
||||
BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"),
|
||||
BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"),
|
||||
BLOCKPLACEWHITELIST("jailing.during.blockPlaceWhiteList"),
|
||||
COMMANDSONJAIL("jailing.jail.commands"),
|
||||
COMMANDSONRELEASE("jailing.release.commands"),
|
||||
COMMANDPENALTY("jailing.during.commandPenalty"),
|
||||
COMMANDPROTECTION("jailing.during.commandProtection"),
|
||||
COMMANDWHITELIST("jailing.during.commandWhitelist"),
|
||||
COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"),
|
||||
CROPTRAMPLINGPENALTY("jailing.during.cropTramplingPenalty"),
|
||||
CROPTRAMPLINGPROTECTION("jailing.during.cropTramplingProtection"),
|
||||
DEBUG("system.debug"),
|
||||
DEFAULTJAIL("jailing.jail.defaultJail"),
|
||||
DELETEINVENTORY("jailing.jail.deleteInventory"),
|
||||
ENDERMENPROTECTION("jails.endermenProtection"),
|
||||
EXPLOSIONPROTECTION("jails.explosionProtection"),
|
||||
FOODCONTROL("jailing.during.foodControl"),
|
||||
FOODCONTROLMAX("jailing.during.foodControlMax"),
|
||||
FOODCONTROLMIN("jailing.during.foodControlMin"),
|
||||
IGNORESLEEPINGSTATE("jailing.during.ignoreSleeping"),
|
||||
JAILSTICKENABLED("jailstick.enabled"),
|
||||
JAILSTICKSTICKS("jailstick.sticks"),
|
||||
JAILDEFAULTTIME("jailing.jail.defaultTime"),
|
||||
JAILEDGAMEMODE("jailing.jail.gameMode"),
|
||||
JAILEDSTOREINVENTORY("jailing.jail.storeInventory"),
|
||||
JAILPAYENABLED("jailpay.enabled"),
|
||||
JAILPAYITEM("jailpay.item"),
|
||||
JAILPAYPRICEPERMINUTE ("jailpay.pricePerMinute"),
|
||||
JAILPAYPRICEINFINITE ("jailpay.priceInfinite"),
|
||||
LOGJAILINGTOCONSOLE("jailing.jail.logToConsole"),
|
||||
MAXAFKTIME("jailing.during.maxAFKTime"),
|
||||
MOVEPENALTY("jailing.during.movePenalty"),
|
||||
MOVEPROTECTION("jailing.during.moveProtection"),
|
||||
PREVENTINTERACTIONBLOCKS("jailing.during.preventInteractionBlocks"),
|
||||
PREVENTINTERACTIONBLOCKSPENALTY("jailing.during.preventInteractionBlocksPenalty"),
|
||||
PREVENTINTERACTIONITEMS("jailing.during.preventInteractionItems"),
|
||||
PREVENTINTERACTIONITEMSPENALTY("jailing.during.preventInteractionItemsPenalty"),
|
||||
PRISONEROPENCHEST("jailing.during.openChest"),
|
||||
RECIEVEMESSAGES("jailing.during.recieveMessages"),
|
||||
RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"),
|
||||
RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"),
|
||||
SCOREBOARDENABLED("jailing.during.scoreboard.enabled"),
|
||||
SCOREBOARDTITLE("jailing.during.scoreboard.title"),
|
||||
SCOREBOARDTIME("jailing.during.scoreboard.time"),
|
||||
TELEPORTONRELEASE("jailing.release.teleport"),
|
||||
UPDATENOTIFICATIONS("system.updateNotifications"),
|
||||
USEBUKKITTIMER("system.useBukkitTimer");
|
||||
|
||||
private String path;
|
||||
|
||||
private Settings(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path this setting is in config.
|
||||
* @return The path where this setting resides in the config.
|
||||
*/
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.enums;
|
||||
|
||||
public enum Settings {
|
||||
AUTOMATICMUTE("jailing.jail.automaticMute"),
|
||||
BROADCASTJAILING("jailing.jail.broadcastJailing"),
|
||||
BLOCKBREAKPENALTY("jailing.during.blockBreakPenalty"),
|
||||
BLOCKBREAKPROTECTION("jailing.during.blockBreakProtection"),
|
||||
BLOCKBREAKWHITELIST("jailing.during.blockBreakWhiteList"),
|
||||
BLOCKPLACEPENALTY("jailing.during.blockPlacePenalty"),
|
||||
BLOCKPLACEPROTECTION("jailing.during.blockPlaceProtection"),
|
||||
BLOCKPLACEWHITELIST("jailing.during.blockPlaceWhiteList"),
|
||||
COMMANDSONJAIL("jailing.jail.commands"),
|
||||
COMMANDSONRELEASE("jailing.release.commands"),
|
||||
COMMANDPENALTY("jailing.during.commandPenalty"),
|
||||
COMMANDPROTECTION("jailing.during.commandProtection"),
|
||||
COMMANDWHITELIST("jailing.during.commandWhitelist"),
|
||||
COUNTDOWNTIMEOFFLINE("jailing.during.countDownTimeWhileOffline"),
|
||||
CROPTRAMPLINGPENALTY("jailing.during.cropTramplingPenalty"),
|
||||
CROPTRAMPLINGPROTECTION("jailing.during.cropTramplingProtection"),
|
||||
DEBUG("system.debug"),
|
||||
DEFAULTJAIL("jailing.jail.defaultJail"),
|
||||
DELETEINVENTORY("jailing.jail.deleteInventory"),
|
||||
ENDERMENPROTECTION("jails.endermenProtection"),
|
||||
EXPLOSIONPROTECTION("jails.explosionProtection"),
|
||||
FOODCONTROL("jailing.during.foodControl"),
|
||||
FOODCONTROLMAX("jailing.during.foodControlMax"),
|
||||
FOODCONTROLMIN("jailing.during.foodControlMin"),
|
||||
IGNORESLEEPINGSTATE("jailing.during.ignoreSleeping"),
|
||||
JAILSTICKENABLED("jailstick.enabled"),
|
||||
JAILSTICKSTICKS("jailstick.sticks"),
|
||||
JAILDEFAULTTIME("jailing.jail.defaultTime"),
|
||||
JAILEDGAMEMODE("jailing.jail.gameMode"),
|
||||
JAILEDSTOREINVENTORY("jailing.jail.storeInventory"),
|
||||
JAILPAYENABLED("jailpay.enabled"),
|
||||
JAILPAYITEM("jailpay.item"),
|
||||
JAILPAYPRICEPERMINUTE ("jailpay.pricePerMinute"),
|
||||
JAILPAYPRICEINFINITE ("jailpay.priceInfinite"),
|
||||
LOGJAILINGTOCONSOLE("jailing.jail.logToConsole"),
|
||||
MAXAFKTIME("jailing.during.maxAFKTime"),
|
||||
MOVEPENALTY("jailing.during.movePenalty"),
|
||||
MOVEPROTECTION("jailing.during.moveProtection"),
|
||||
PREVENTINTERACTIONBLOCKS("jailing.during.preventInteractionBlocks"),
|
||||
PREVENTINTERACTIONBLOCKSPENALTY("jailing.during.preventInteractionBlocksPenalty"),
|
||||
PREVENTINTERACTIONITEMS("jailing.during.preventInteractionItems"),
|
||||
PREVENTINTERACTIONITEMSPENALTY("jailing.during.preventInteractionItemsPenalty"),
|
||||
PRISONEROPENCHEST("jailing.during.openChest"),
|
||||
RECIEVEMESSAGES("jailing.during.recieveMessages"),
|
||||
RELEASETOPREVIOUSPOSITION("jailing.release.backToPreviousPosition"),
|
||||
RESTOREPREVIOUSGAMEMODE("jailing.release.restorePreviousGameMode"),
|
||||
SCOREBOARDENABLED("jailing.during.scoreboard.enabled"),
|
||||
SCOREBOARDTITLE("jailing.during.scoreboard.title"),
|
||||
SCOREBOARDTIME("jailing.during.scoreboard.time"),
|
||||
TELEPORTONRELEASE("jailing.release.teleport"),
|
||||
UPDATENOTIFICATIONS("system.updateNotifications"),
|
||||
USEBUKKITTIMER("system.useBukkitTimer");
|
||||
|
||||
private String path;
|
||||
|
||||
private Settings(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path this setting is in config.
|
||||
* @return The path where this setting resides in the config.
|
||||
*/
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
|
@ -1,125 +1,125 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.Stick;
|
||||
|
||||
/**
|
||||
* Event thrown before we a player is jailed by someone hitting them with a {@link Stick jail stick}.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called right before we actually jail a player, and is cancellable.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerJailedByJailStickEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
private String jailer, cancelMsg;
|
||||
private Stick stick;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerJailedByJailStickEvent prisoner jailed by a jail stick event} for the given player before they get sent to jail.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
* @param jailer The name of what jailed this prisoner.
|
||||
* @param stick The {@link Stick jail stick} used.
|
||||
*/
|
||||
public PrePrisonerJailedByJailStickEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, String jailer, Stick stick) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
this.jailer = jailer;
|
||||
this.stick = stick;
|
||||
this.cancelMsg = "";
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being sent to. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell we're going to be sending the prisoner to. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Sets the cell we're going to be sending the prisoner to. */
|
||||
public void setCell(Cell cell) {
|
||||
this.cell = cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being jailed. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets the jailer who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.jailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets who jailed this prisoner.
|
||||
*
|
||||
* @param jailer The name to put who is the jailer for this prisoner.
|
||||
*/
|
||||
public void setJailer(String jailer) {
|
||||
this.jailer = jailer;
|
||||
}
|
||||
|
||||
/** Gets the jail stick used. */
|
||||
public Stick getJailStick() {
|
||||
return this.stick;
|
||||
}
|
||||
|
||||
/** Checks whether this event is cancelled or not. */
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/** Sets whether this event should be cancelled. */
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
/** Returns the cancelled message. */
|
||||
public String getCancelledMessage() {
|
||||
return this.cancelMsg;
|
||||
}
|
||||
|
||||
/** Sets the cancelled message. */
|
||||
public void setCancelledMessage(String msg) {
|
||||
this.cancelMsg = msg;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.Stick;
|
||||
|
||||
/**
|
||||
* Event thrown before we a player is jailed by someone hitting them with a {@link Stick jail stick}.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called right before we actually jail a player, and is cancellable.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerJailedByJailStickEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
private String jailer, cancelMsg;
|
||||
private Stick stick;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerJailedByJailStickEvent prisoner jailed by a jail stick event} for the given player before they get sent to jail.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
* @param jailer The name of what jailed this prisoner.
|
||||
* @param stick The {@link Stick jail stick} used.
|
||||
*/
|
||||
public PrePrisonerJailedByJailStickEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, String jailer, Stick stick) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
this.jailer = jailer;
|
||||
this.stick = stick;
|
||||
this.cancelMsg = "";
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being sent to. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell we're going to be sending the prisoner to. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Sets the cell we're going to be sending the prisoner to. */
|
||||
public void setCell(Cell cell) {
|
||||
this.cell = cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being jailed. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets the jailer who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.jailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets who jailed this prisoner.
|
||||
*
|
||||
* @param jailer The name to put who is the jailer for this prisoner.
|
||||
*/
|
||||
public void setJailer(String jailer) {
|
||||
this.jailer = jailer;
|
||||
}
|
||||
|
||||
/** Gets the jail stick used. */
|
||||
public Stick getJailStick() {
|
||||
return this.stick;
|
||||
}
|
||||
|
||||
/** Checks whether this event is cancelled or not. */
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/** Sets whether this event should be cancelled. */
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
/** Returns the cancelled message. */
|
||||
public String getCancelledMessage() {
|
||||
return this.cancelMsg;
|
||||
}
|
||||
|
||||
/** Sets the cancelled message. */
|
||||
public void setCancelledMessage(String msg) {
|
||||
this.cancelMsg = msg;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,124 +1,124 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown before we are jailing a player, both offline and online players.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called right before we actually jail a player, and is cancellable, whether the player is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerJailedEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private boolean online;
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
private String jailer, cancelMsg;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerJailedEvent prisoner jailed event} for the given player before they get sent to jail.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
* @param online Whether the player is online or not.
|
||||
* @param jailer The name of what jailed this prisoner.
|
||||
*/
|
||||
public PrePrisonerJailedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, boolean online, String jailer) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
this.online = online;
|
||||
this.jailer = jailer;
|
||||
this.cancelMsg = "";
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being sent to. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell we're going to be sending the prisoner to. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Sets the cell we're going to be sending the prisoner to. */
|
||||
public void setCell(Cell cell) {
|
||||
this.cell = cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being jailed <strong>but will return null if {@link #isOnline()} returns false</strong>. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner being jailed is online or not. */
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
/** Gets the jailer who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.jailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets who jailed this prisoner.
|
||||
*
|
||||
* @param jailer The name to put who is the jailer for this prisoner.
|
||||
*/
|
||||
public void setJailer(String jailer) {
|
||||
this.jailer = jailer;
|
||||
}
|
||||
|
||||
/** Checks whether this event is cancelled or not. */
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/** Sets whether this event should be cancelled. */
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
/** Returns the cancelled message. */
|
||||
public String getCancelledMessage() {
|
||||
return this.cancelMsg;
|
||||
}
|
||||
|
||||
/** Sets the cancelled message. */
|
||||
public void setCancelledMessage(String msg) {
|
||||
this.cancelMsg = msg;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown before we are jailing a player, both offline and online players.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called right before we actually jail a player, and is cancellable, whether the player is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerJailedEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private boolean online;
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
private String jailer, cancelMsg;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerJailedEvent prisoner jailed event} for the given player before they get sent to jail.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
* @param online Whether the player is online or not.
|
||||
* @param jailer The name of what jailed this prisoner.
|
||||
*/
|
||||
public PrePrisonerJailedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, boolean online, String jailer) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
this.online = online;
|
||||
this.jailer = jailer;
|
||||
this.cancelMsg = "";
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being sent to. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell we're going to be sending the prisoner to. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Sets the cell we're going to be sending the prisoner to. */
|
||||
public void setCell(Cell cell) {
|
||||
this.cell = cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being jailed <strong>but will return null if {@link #isOnline()} returns false</strong>. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner being jailed is online or not. */
|
||||
public boolean isOnline() {
|
||||
return this.online;
|
||||
}
|
||||
|
||||
/** Gets the jailer who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.jailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets who jailed this prisoner.
|
||||
*
|
||||
* @param jailer The name to put who is the jailer for this prisoner.
|
||||
*/
|
||||
public void setJailer(String jailer) {
|
||||
this.jailer = jailer;
|
||||
}
|
||||
|
||||
/** Checks whether this event is cancelled or not. */
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/** Sets whether this event should be cancelled. */
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
/** Returns the cancelled message. */
|
||||
public String getCancelledMessage() {
|
||||
return this.cancelMsg;
|
||||
}
|
||||
|
||||
/** Sets the cancelled message. */
|
||||
public void setCancelledMessage(String msg) {
|
||||
this.cancelMsg = msg;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,73 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is released.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called before everything for the releasing takes place.
|
||||
* This event is called for informative purposes, see {@link PrisonerReleasedEvent}
|
||||
* for the event called after they get teleported out and all that fancy stuff.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerReleasedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerReleasedEvent pre-prisoner released event} for the given player.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrePrisonerReleasedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell where the prisoner was jailed in, null if they weren't in one. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being released. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is released.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called before everything for the releasing takes place.
|
||||
* This event is called for informative purposes, see {@link PrisonerReleasedEvent}
|
||||
* for the event called after they get teleported out and all that fancy stuff.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerReleasedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerReleasedEvent pre-prisoner released event} for the given player.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrePrisonerReleasedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell where the prisoner was jailed in, null if they weren't in one. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being released. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,152 +1,152 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown before we transfer a prisoner, both offline and online prisoner.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called right before we actually transfer a prisoner, and is cancellable, whether the prisoner is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerTransferredEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private Jail originalJail, targetJail;
|
||||
private Cell originalCell, targetCell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
private String transferor, cancelMsg;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerTransferredEvent prisoner transferred event} for the given player before they get transferred to their jail and cell.
|
||||
*
|
||||
* @param originalJail The jail the prisoner is coming from.
|
||||
* @param originalCell The cell the prisoner is coming from, can be null.
|
||||
* @param targetJail The jail the prisoner is going to.
|
||||
* @param targetCell The cell the prisoner is going to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
* @param transferor The name of what is transferring this prisoner.
|
||||
*/
|
||||
public PrePrisonerTransferredEvent(Jail originalJail, Cell originalCell, Jail targetJail, Cell targetCell, Prisoner prisoner, Player player, String transferor) {
|
||||
this.originalJail = originalJail;
|
||||
this.originalCell = originalCell;
|
||||
this.targetJail = targetJail;
|
||||
this.targetCell = targetCell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
this.transferor = transferor;
|
||||
this.cancelMsg = "";
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getOriginalJail() {
|
||||
return this.originalJail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is coming from, can be null. */
|
||||
public Cell getOriginalCell() {
|
||||
return this.originalCell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
||||
public Jail getTargetJail() {
|
||||
return this.targetJail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target jail where this prisoner is being sent to.
|
||||
*
|
||||
* @param jail The {@link Jail} this prisoner should be sent to instead of what it was.
|
||||
*/
|
||||
public void setTargetJail(Jail jail) {
|
||||
this.targetJail = jail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is being sent to, can be null.
|
||||
*
|
||||
* Will return null if the cell is not in the targetJail.
|
||||
*/
|
||||
public Cell getTargetCell() {
|
||||
if(this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target {@link Cell} this prisoner is being sent to.
|
||||
*
|
||||
* @param cell The {@link Cell} this prisoner should be sent to instead of what it was.
|
||||
*/
|
||||
public void setTargetCell(Cell cell) {
|
||||
this.targetCell = cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being transferred <strong>but will return null if {@link #isOnline()} returns false</strong>. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner being transferred is online or not. */
|
||||
public boolean isOnline() {
|
||||
return player == null;
|
||||
}
|
||||
|
||||
/** Gets the name of what is transferring this prisoner. */
|
||||
public String getTransferor() {
|
||||
return this.transferor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prisoner whom the data should say jailed this prisoner.
|
||||
*
|
||||
* @param transferor The name to put who is the jailer for this prisoner.
|
||||
*/
|
||||
public void setTransferor(String transferor) {
|
||||
this.transferor = transferor;
|
||||
}
|
||||
|
||||
/** Checks whether this event is cancelled or not. */
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/** Sets whether this event should be cancelled. */
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
/** Returns the cancelled message. */
|
||||
public String getCancelledMessage() {
|
||||
return this.cancelMsg;
|
||||
}
|
||||
|
||||
/** Sets the cancelled message. */
|
||||
public void setCancelledMessage(String msg) {
|
||||
this.cancelMsg = msg;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown before we transfer a prisoner, both offline and online prisoner.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called right before we actually transfer a prisoner, and is cancellable, whether the prisoner is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrePrisonerTransferredEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private Jail originalJail, targetJail;
|
||||
private Cell originalCell, targetCell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
private String transferor, cancelMsg;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrePrisonerTransferredEvent prisoner transferred event} for the given player before they get transferred to their jail and cell.
|
||||
*
|
||||
* @param originalJail The jail the prisoner is coming from.
|
||||
* @param originalCell The cell the prisoner is coming from, can be null.
|
||||
* @param targetJail The jail the prisoner is going to.
|
||||
* @param targetCell The cell the prisoner is going to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
* @param transferor The name of what is transferring this prisoner.
|
||||
*/
|
||||
public PrePrisonerTransferredEvent(Jail originalJail, Cell originalCell, Jail targetJail, Cell targetCell, Prisoner prisoner, Player player, String transferor) {
|
||||
this.originalJail = originalJail;
|
||||
this.originalCell = originalCell;
|
||||
this.targetJail = targetJail;
|
||||
this.targetCell = targetCell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
this.transferor = transferor;
|
||||
this.cancelMsg = "";
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getOriginalJail() {
|
||||
return this.originalJail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is coming from, can be null. */
|
||||
public Cell getOriginalCell() {
|
||||
return this.originalCell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
||||
public Jail getTargetJail() {
|
||||
return this.targetJail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target jail where this prisoner is being sent to.
|
||||
*
|
||||
* @param jail The {@link Jail} this prisoner should be sent to instead of what it was.
|
||||
*/
|
||||
public void setTargetJail(Jail jail) {
|
||||
this.targetJail = jail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is being sent to, can be null.
|
||||
*
|
||||
* Will return null if the cell is not in the targetJail.
|
||||
*/
|
||||
public Cell getTargetCell() {
|
||||
if(this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target {@link Cell} this prisoner is being sent to.
|
||||
*
|
||||
* @param cell The {@link Cell} this prisoner should be sent to instead of what it was.
|
||||
*/
|
||||
public void setTargetCell(Cell cell) {
|
||||
this.targetCell = cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being transferred <strong>but will return null if {@link #isOnline()} returns false</strong>. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner being transferred is online or not. */
|
||||
public boolean isOnline() {
|
||||
return player == null;
|
||||
}
|
||||
|
||||
/** Gets the name of what is transferring this prisoner. */
|
||||
public String getTransferor() {
|
||||
return this.transferor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prisoner whom the data should say jailed this prisoner.
|
||||
*
|
||||
* @param transferor The name to put who is the jailer for this prisoner.
|
||||
*/
|
||||
public void setTransferor(String transferor) {
|
||||
this.transferor = transferor;
|
||||
}
|
||||
|
||||
/** Checks whether this event is cancelled or not. */
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/** Sets whether this event should be cancelled. */
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
/** Returns the cancelled message. */
|
||||
public String getCancelledMessage() {
|
||||
return this.cancelMsg;
|
||||
}
|
||||
|
||||
/** Sets the cancelled message. */
|
||||
public void setCancelledMessage(String msg) {
|
||||
this.cancelMsg = msg;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,78 +1,78 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is put into jail.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called after everything for the jailing takes place.
|
||||
* This event is called for informative purposes, see {@link PrePrisonerJailedEvent}
|
||||
* for the event called before they teleported in and all that fancy stuff.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrisonerJailedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrisonerJailedEvent prisoner jailed event} for the given player.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrisonerJailedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being sent to. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell we're going to be sending the prisoner to, can be null. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being jailed. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets the jailer who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.prisoner.getJailer();
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is put into jail.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called after everything for the jailing takes place.
|
||||
* This event is called for informative purposes, see {@link PrePrisonerJailedEvent}
|
||||
* for the event called before they teleported in and all that fancy stuff.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrisonerJailedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrisonerJailedEvent prisoner jailed event} for the given player.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrisonerJailedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being sent to. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell we're going to be sending the prisoner to, can be null. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being jailed. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets the jailer who jailed this prisoner. */
|
||||
public String getJailer() {
|
||||
return this.prisoner.getJailer();
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,73 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is released.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called after everything for the releasing takes place.
|
||||
* This event is called for informative purposes, see {@link PrePrisonerReleasedEvent}
|
||||
* for the event called before they teleported out and all that fancy stuff.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrisonerReleasedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrisonerReleasedEvent prisoner released event} for the given player.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrisonerReleasedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell where the prisoner was jailed in, null if they weren't in one. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being released. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after a prisoner is released.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called after everything for the releasing takes place.
|
||||
* This event is called for informative purposes, see {@link PrePrisonerReleasedEvent}
|
||||
* for the event called before they teleported out and all that fancy stuff.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrisonerReleasedEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail jail;
|
||||
private Cell cell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrisonerReleasedEvent prisoner released event} for the given player.
|
||||
*
|
||||
* @param jail The jail the prisoner will be jailed at.
|
||||
* @param cell The cell we're going to be sending the prisoner to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrisonerReleasedEvent(Jail jail, Cell cell, Prisoner prisoner, Player player) {
|
||||
this.jail = jail;
|
||||
this.cell = cell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getJail() {
|
||||
return this.jail;
|
||||
}
|
||||
|
||||
/** Gets the cell where the prisoner was jailed in, null if they weren't in one. */
|
||||
public Cell getCell() {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being released. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +1,94 @@
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after we transfer a prisoner, both an offline and an online prisoner.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called after we transfer the prisoner whether the prisoner is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrisonerTransferredEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail originalJail, targetJail;
|
||||
private Cell originalCell, targetCell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrisonerTransferredEvent prisoner transferred event} for the given player after they get transferred to their new jail and cell.
|
||||
*
|
||||
* @param originalJail The jail the prisoner is coming from.
|
||||
* @param originalCell The cell the prisoner is coming from, can be null.
|
||||
* @param targetJail The jail the prisoner went to.
|
||||
* @param targetCell The cell the prisoner went to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrisonerTransferredEvent(Jail originalJail, Cell originalCell, Jail targetJail, Cell targetCell, Prisoner prisoner, Player player) {
|
||||
this.originalJail = originalJail;
|
||||
this.originalCell = originalCell;
|
||||
this.targetJail = targetJail;
|
||||
this.targetCell = targetCell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getOriginalJail() {
|
||||
return this.originalJail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is coming from, can be null. */
|
||||
public Cell getOriginalCell() {
|
||||
return this.originalCell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
||||
public Jail getTargetJail() {
|
||||
return this.targetJail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is being sent to, can be null.
|
||||
*
|
||||
* Will return null if the cell is not in the targetJail.
|
||||
*/
|
||||
public Cell getTargetCell() {
|
||||
if(this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being transferred <strong>but will return null if {@link #isOnline()} returns false</strong>. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner being transferred is online or not. */
|
||||
public boolean isOnline() {
|
||||
return player == null;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
|
||||
/**
|
||||
* Event thrown after we transfer a prisoner, both an offline and an online prisoner.
|
||||
*
|
||||
* <p />
|
||||
*
|
||||
* This event is called after we transfer the prisoner whether the prisoner is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class PrisonerTransferredEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Jail originalJail, targetJail;
|
||||
private Cell originalCell, targetCell;
|
||||
private Prisoner prisoner;
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PrisonerTransferredEvent prisoner transferred event} for the given player after they get transferred to their new jail and cell.
|
||||
*
|
||||
* @param originalJail The jail the prisoner is coming from.
|
||||
* @param originalCell The cell the prisoner is coming from, can be null.
|
||||
* @param targetJail The jail the prisoner went to.
|
||||
* @param targetCell The cell the prisoner went to, can be null.
|
||||
* @param prisoner The prisoner data.
|
||||
* @param player The player being jailed.
|
||||
*/
|
||||
public PrisonerTransferredEvent(Jail originalJail, Cell originalCell, Jail targetJail, Cell targetCell, Prisoner prisoner, Player player) {
|
||||
this.originalJail = originalJail;
|
||||
this.originalCell = originalCell;
|
||||
this.targetJail = targetJail;
|
||||
this.targetCell = targetCell;
|
||||
this.prisoner = prisoner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is coming from. */
|
||||
public Jail getOriginalJail() {
|
||||
return this.originalJail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is coming from, can be null. */
|
||||
public Cell getOriginalCell() {
|
||||
return this.originalCell;
|
||||
}
|
||||
|
||||
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
||||
public Jail getTargetJail() {
|
||||
return this.targetJail;
|
||||
}
|
||||
|
||||
/** Gets the {@link Cell} this prisoner is being sent to, can be null.
|
||||
*
|
||||
* Will return null if the cell is not in the targetJail.
|
||||
*/
|
||||
public Cell getTargetCell() {
|
||||
if(this.targetJail.isValidCell(this.targetCell.getName())) return this.targetCell;
|
||||
else return null;
|
||||
}
|
||||
|
||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||
public Prisoner getPrisoner() {
|
||||
return this.prisoner;
|
||||
}
|
||||
|
||||
/** Gets the instance of the player being transferred <strong>but will return null if {@link #isOnline()} returns false</strong>. */
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/** Gets whether the prisoner being transferred is online or not. */
|
||||
public boolean isOnline() {
|
||||
return player == null;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,444 +1,444 @@
|
||||
package com.graywolf336.jail.legacy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
/**
|
||||
* Manages the old data from Jail 2.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class LegacyManager {
|
||||
private JailMain pl;
|
||||
private YamlConfiguration global;
|
||||
private boolean wasConverted;
|
||||
|
||||
public LegacyManager(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.wasConverted = false;
|
||||
}
|
||||
|
||||
/** Returns true/false if the old config, global.yml, exists and needs to be converted. */
|
||||
public boolean doWeNeedToConvert() {
|
||||
return new File(pl.getDataFolder(), "global.yml").exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we converted anything and it was successful.
|
||||
*
|
||||
* @return true if everything converted successfully, was if not.
|
||||
*/
|
||||
public boolean wasAnythingConverted() {
|
||||
return this.wasConverted;
|
||||
}
|
||||
|
||||
public boolean convertOldData() {
|
||||
File f = new File(pl.getDataFolder(), "global.yml");
|
||||
|
||||
if(f.exists()) {
|
||||
global = new YamlConfiguration();
|
||||
try {
|
||||
global.load(f);
|
||||
} catch (FileNotFoundException e) {
|
||||
//e.printStackTrace();
|
||||
pl.getLogger().severe("Unable to load the old global config, file not found.");
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
pl.getLogger().severe("Unable to load the old global config: " + e.getMessage());
|
||||
} catch (InvalidConfigurationException e) {
|
||||
//e.printStackTrace();
|
||||
pl.getLogger().severe("Unable to load the old global config: " + e.getMessage());
|
||||
}
|
||||
}else {
|
||||
pl.debug("The old config file, global.yml, was not found so not loading anything.");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
pl.getLogger().info("Starting to convert Jail 2.x data to Jail 3.0, this does use a blocking call (getOfflinePlayer) so expect the server to be held up until we are finished...");
|
||||
loadOldConfig();
|
||||
loadOldData();
|
||||
moveOldConfigs();
|
||||
this.wasConverted = true;
|
||||
pl.getLogger().info("...finished converting configs and data.");
|
||||
return true;
|
||||
}catch (Exception e) {
|
||||
if(pl.inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pl.debug(e.getMessage());
|
||||
pl.getLogger().severe("Failed to load the old configuration for some reason.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void loadOldConfig() {
|
||||
FileConfiguration c = pl.getConfig();
|
||||
|
||||
int count = 0;
|
||||
for(OldSetting s : OldSetting.values()) {
|
||||
switch(s) {
|
||||
case Debug:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.DEBUG.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
//Only set it true if the old config had true, this way we can still hold the debuggin over
|
||||
//if the old config had it set to false but the new one has it set to true (until a restart/reload)
|
||||
if(c.getBoolean(Settings.DEBUG.getPath())) pl.setDebugging(true);
|
||||
pl.debug(Settings.DEBUG.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BroadcastJailMessage:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BROADCASTJAILING.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.BROADCASTJAILING.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case AllowUpdateNotifications:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.UPDATENOTIFICATIONS.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.UPDATENOTIFICATIONS.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case ExecutedCommandsOnJail:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDSONJAIL.getPath(), OldSettings.getGlobalList(global, s));
|
||||
pl.debug(Settings.COMMANDSONJAIL.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case ExecutedCommandsOnRelease:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDSONRELEASE.getPath(), OldSettings.getGlobalList(global, s));
|
||||
pl.debug(Settings.COMMANDSONRELEASE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case AutomaticMute:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.AUTOMATICMUTE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.AUTOMATICMUTE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case StoreInventory:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILEDSTOREINVENTORY.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.JAILEDSTOREINVENTORY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case CanPrisonerOpenHisChest:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.PRISONEROPENCHEST.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.PRISONEROPENCHEST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case LogJailingIntoConsole:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.LOGJAILINGTOCONSOLE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.LOGJAILINGTOCONSOLE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case CountdownTimeWhenOffline:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COUNTDOWNTIMEOFFLINE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.COUNTDOWNTIMEOFFLINE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case ReleaseBackToPreviousPosition:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.RELEASETOPREVIOUSPOSITION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.RELEASETOPREVIOUSPOSITION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case IgnorePrisonersSleepingState:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.IGNORESLEEPINGSTATE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.IGNORESLEEPINGSTATE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case TeleportPrisonerOnRelease:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.TELEPORTONRELEASE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.TELEPORTONRELEASE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case DefaultJailTime:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILDEFAULTTIME.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.JAILDEFAULTTIME.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case UseBukkitSchedulerTimer:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.USEBUKKITTIMER.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.USEBUKKITTIMER.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableJailStick:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILSTICKENABLED.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.JAILSTICKENABLED.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case JailStickParameters:
|
||||
if(global.contains(s.getString())) {
|
||||
LinkedList<String> sticks = new LinkedList<String>();
|
||||
for (String i : OldSettings.getGlobalString(global, s).split(";")) {
|
||||
String[] info = i.split(",");
|
||||
//item id,range,time,jail name,reason
|
||||
Material m = Material.getMaterial(Integer.valueOf(info[0]).intValue());
|
||||
|
||||
//item name,time,jail name,reason
|
||||
sticks.push(m.toString().toLowerCase() + "," + info[2] + "," + info[3] + "," + info[4]);
|
||||
}
|
||||
c.set(Settings.JAILSTICKSTICKS.getPath(), sticks);
|
||||
pl.debug(Settings.JAILSTICKSTICKS.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableBlockDestroyProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKBREAKPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.BLOCKBREAKPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockDestroyPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKBREAKPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.BLOCKBREAKPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockDestroyProtectionExceptions:
|
||||
if(global.contains(s.getString())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> exceptions = (List<String>) OldSettings.getGlobalList(global, s);
|
||||
LinkedList<String> whitelist = new LinkedList<String>();
|
||||
for(String e : exceptions) {
|
||||
whitelist.add(Material.getMaterial(Integer.valueOf(e).intValue()).toString().toLowerCase());
|
||||
}
|
||||
|
||||
c.set(Settings.BLOCKBREAKWHITELIST.getPath(), whitelist);
|
||||
pl.debug(Settings.BLOCKBREAKWHITELIST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableBlockPlaceProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKPLACEPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.BLOCKPLACEPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockPlacePenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKPLACEPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.BLOCKPLACEPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockPlaceProtectionExceptions:
|
||||
if(global.contains(s.getString())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> exceptions = (List<String>) OldSettings.getGlobalList(global, s);
|
||||
LinkedList<String> whitelist = new LinkedList<String>();
|
||||
for(String e : exceptions) {
|
||||
whitelist.add(Material.getMaterial(Integer.valueOf(e).intValue()).toString().toLowerCase());
|
||||
}
|
||||
|
||||
c.set(Settings.BLOCKPLACEWHITELIST.getPath(), whitelist);
|
||||
pl.debug(Settings.BLOCKPLACEWHITELIST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnablePlayerMoveProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.MOVEPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.MOVEPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PlayerMoveProtectionPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.MOVEPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.MOVEPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case WhitelistedCommands:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDWHITELIST.getPath(), OldSettings.getGlobalList(global, s));
|
||||
pl.debug(Settings.COMMANDWHITELIST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case CommandProtectionPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.COMMANDPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case InteractionPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableExplosionProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.EXPLOSIONPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.EXPLOSIONPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableFoodControl:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.FOODCONTROL.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.FOODCONTROL.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case FoodControlMinimumFood:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.FOODCONTROLMIN.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.FOODCONTROLMIN.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case FoodControlMaximumFood:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.FOODCONTROLMAX.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.FOODCONTROLMAX.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PrisonersRecieveMessages:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.RECIEVEMESSAGES.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.RECIEVEMESSAGES.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case UseMySQL:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set("storage.type", OldSettings.getGlobalBoolean(global, s) ? "mysql" : "sqlite");
|
||||
pl.debug(Settings.RECIEVEMESSAGES.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case MySQLConn:
|
||||
if(global.contains(s.getString())) {
|
||||
//jdbc:mysql://localhost:3306/minecraft
|
||||
String con = OldSettings.getGlobalString(global, s);
|
||||
String a = con.split("//")[1];
|
||||
//localhost 3306/minecraft
|
||||
String[] b1 = a.split(":");
|
||||
//3306 minecraft
|
||||
String[] b2 = b1[1].split("/");
|
||||
|
||||
c.set("storage.mysql.host", b1[0]);
|
||||
c.set("storage.mysql.port", b2[0]);
|
||||
c.set("storage.mysql.database", b2[1]);
|
||||
|
||||
pl.debug("storage.mysql <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case MySQLUsername:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set("storage.mysql.username", OldSettings.getGlobalString(global, s));
|
||||
pl.debug("storage.mysql.username <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case MySQLPassword:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set("storage.mysql.password", OldSettings.getGlobalString(global, s));
|
||||
pl.debug("storage.mysql.password <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PricePerMinute:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILPAYPRICEPERMINUTE.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.JAILPAYPRICEPERMINUTE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
case PriceForInfiniteJail:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILPAYPRICEINFINITE.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.JAILPAYPRICEINFINITE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
case JailPayCurrency:
|
||||
if(global.contains(s.getString())) {
|
||||
Material mat = Material.getMaterial(OldSettings.getGlobalInt(global, s));
|
||||
if(mat != null) {
|
||||
c.set(Settings.JAILPAYITEM.getPath(), mat.toString().toLowerCase());
|
||||
pl.debug(Settings.JAILPAYPRICEINFINITE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pl.saveConfig();
|
||||
pl.getLogger().info("Converted " + count + " old config value" + (count == 1 ? "" : "s") + ".");
|
||||
}
|
||||
|
||||
private void loadOldData() throws SQLException {
|
||||
OldInputOutput o = new OldInputOutput(pl, global);
|
||||
|
||||
o.LoadJails();
|
||||
o.LoadPrisoners();
|
||||
o.LoadCells();
|
||||
o.freeConnection();
|
||||
}
|
||||
|
||||
private void moveOldConfigs() throws IOException {
|
||||
FileUtils.moveFileToDirectory(new File(pl.getDataFolder(), "global.yml"), new File(pl.getDataFolder() + File.separator + "preJail3Data"), true);
|
||||
FileUtils.moveFileToDirectory(new File(pl.getDataFolder(), "jails.yml"), new File(pl.getDataFolder() + File.separator + "preJail3Data"), true);
|
||||
FileUtils.moveFileToDirectory(new File(pl.getDataFolder(), "jailLog.txt"), new File(pl.getDataFolder() + File.separator + "preJail3Data"), true);
|
||||
|
||||
File sqlite = new File(pl.getDataFolder(), "jail.sqlite");
|
||||
if(sqlite.exists()) {
|
||||
FileUtils.moveFileToDirectory(sqlite, new File(pl.getDataFolder() + File.separator + "oldData"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.legacy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
/**
|
||||
* Manages the old data from Jail 2.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class LegacyManager {
|
||||
private JailMain pl;
|
||||
private YamlConfiguration global;
|
||||
private boolean wasConverted;
|
||||
|
||||
public LegacyManager(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.wasConverted = false;
|
||||
}
|
||||
|
||||
/** Returns true/false if the old config, global.yml, exists and needs to be converted. */
|
||||
public boolean doWeNeedToConvert() {
|
||||
return new File(pl.getDataFolder(), "global.yml").exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we converted anything and it was successful.
|
||||
*
|
||||
* @return true if everything converted successfully, was if not.
|
||||
*/
|
||||
public boolean wasAnythingConverted() {
|
||||
return this.wasConverted;
|
||||
}
|
||||
|
||||
public boolean convertOldData() {
|
||||
File f = new File(pl.getDataFolder(), "global.yml");
|
||||
|
||||
if(f.exists()) {
|
||||
global = new YamlConfiguration();
|
||||
try {
|
||||
global.load(f);
|
||||
} catch (FileNotFoundException e) {
|
||||
//e.printStackTrace();
|
||||
pl.getLogger().severe("Unable to load the old global config, file not found.");
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
pl.getLogger().severe("Unable to load the old global config: " + e.getMessage());
|
||||
} catch (InvalidConfigurationException e) {
|
||||
//e.printStackTrace();
|
||||
pl.getLogger().severe("Unable to load the old global config: " + e.getMessage());
|
||||
}
|
||||
}else {
|
||||
pl.debug("The old config file, global.yml, was not found so not loading anything.");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
pl.getLogger().info("Starting to convert Jail 2.x data to Jail 3.0, this does use a blocking call (getOfflinePlayer) so expect the server to be held up until we are finished...");
|
||||
loadOldConfig();
|
||||
loadOldData();
|
||||
moveOldConfigs();
|
||||
this.wasConverted = true;
|
||||
pl.getLogger().info("...finished converting configs and data.");
|
||||
return true;
|
||||
}catch (Exception e) {
|
||||
if(pl.inDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pl.debug(e.getMessage());
|
||||
pl.getLogger().severe("Failed to load the old configuration for some reason.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void loadOldConfig() {
|
||||
FileConfiguration c = pl.getConfig();
|
||||
|
||||
int count = 0;
|
||||
for(OldSetting s : OldSetting.values()) {
|
||||
switch(s) {
|
||||
case Debug:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.DEBUG.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
//Only set it true if the old config had true, this way we can still hold the debuggin over
|
||||
//if the old config had it set to false but the new one has it set to true (until a restart/reload)
|
||||
if(c.getBoolean(Settings.DEBUG.getPath())) pl.setDebugging(true);
|
||||
pl.debug(Settings.DEBUG.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BroadcastJailMessage:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BROADCASTJAILING.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.BROADCASTJAILING.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case AllowUpdateNotifications:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.UPDATENOTIFICATIONS.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.UPDATENOTIFICATIONS.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case ExecutedCommandsOnJail:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDSONJAIL.getPath(), OldSettings.getGlobalList(global, s));
|
||||
pl.debug(Settings.COMMANDSONJAIL.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case ExecutedCommandsOnRelease:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDSONRELEASE.getPath(), OldSettings.getGlobalList(global, s));
|
||||
pl.debug(Settings.COMMANDSONRELEASE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case AutomaticMute:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.AUTOMATICMUTE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.AUTOMATICMUTE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case StoreInventory:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILEDSTOREINVENTORY.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.JAILEDSTOREINVENTORY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case CanPrisonerOpenHisChest:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.PRISONEROPENCHEST.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.PRISONEROPENCHEST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case LogJailingIntoConsole:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.LOGJAILINGTOCONSOLE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.LOGJAILINGTOCONSOLE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case CountdownTimeWhenOffline:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COUNTDOWNTIMEOFFLINE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.COUNTDOWNTIMEOFFLINE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case ReleaseBackToPreviousPosition:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.RELEASETOPREVIOUSPOSITION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.RELEASETOPREVIOUSPOSITION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case IgnorePrisonersSleepingState:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.IGNORESLEEPINGSTATE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.IGNORESLEEPINGSTATE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case TeleportPrisonerOnRelease:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.TELEPORTONRELEASE.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.TELEPORTONRELEASE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case DefaultJailTime:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILDEFAULTTIME.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.JAILDEFAULTTIME.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case UseBukkitSchedulerTimer:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.USEBUKKITTIMER.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.USEBUKKITTIMER.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableJailStick:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILSTICKENABLED.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.JAILSTICKENABLED.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case JailStickParameters:
|
||||
if(global.contains(s.getString())) {
|
||||
LinkedList<String> sticks = new LinkedList<String>();
|
||||
for (String i : OldSettings.getGlobalString(global, s).split(";")) {
|
||||
String[] info = i.split(",");
|
||||
//item id,range,time,jail name,reason
|
||||
Material m = Material.getMaterial(Integer.valueOf(info[0]).intValue());
|
||||
|
||||
//item name,time,jail name,reason
|
||||
sticks.push(m.toString().toLowerCase() + "," + info[2] + "," + info[3] + "," + info[4]);
|
||||
}
|
||||
c.set(Settings.JAILSTICKSTICKS.getPath(), sticks);
|
||||
pl.debug(Settings.JAILSTICKSTICKS.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableBlockDestroyProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKBREAKPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.BLOCKBREAKPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockDestroyPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKBREAKPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.BLOCKBREAKPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockDestroyProtectionExceptions:
|
||||
if(global.contains(s.getString())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> exceptions = (List<String>) OldSettings.getGlobalList(global, s);
|
||||
LinkedList<String> whitelist = new LinkedList<String>();
|
||||
for(String e : exceptions) {
|
||||
whitelist.add(Material.getMaterial(Integer.valueOf(e).intValue()).toString().toLowerCase());
|
||||
}
|
||||
|
||||
c.set(Settings.BLOCKBREAKWHITELIST.getPath(), whitelist);
|
||||
pl.debug(Settings.BLOCKBREAKWHITELIST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableBlockPlaceProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKPLACEPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.BLOCKPLACEPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockPlacePenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.BLOCKPLACEPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.BLOCKPLACEPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case BlockPlaceProtectionExceptions:
|
||||
if(global.contains(s.getString())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> exceptions = (List<String>) OldSettings.getGlobalList(global, s);
|
||||
LinkedList<String> whitelist = new LinkedList<String>();
|
||||
for(String e : exceptions) {
|
||||
whitelist.add(Material.getMaterial(Integer.valueOf(e).intValue()).toString().toLowerCase());
|
||||
}
|
||||
|
||||
c.set(Settings.BLOCKPLACEWHITELIST.getPath(), whitelist);
|
||||
pl.debug(Settings.BLOCKPLACEWHITELIST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnablePlayerMoveProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.MOVEPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.MOVEPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PlayerMoveProtectionPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.MOVEPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.MOVEPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case WhitelistedCommands:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDWHITELIST.getPath(), OldSettings.getGlobalList(global, s));
|
||||
pl.debug(Settings.COMMANDWHITELIST.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case CommandProtectionPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.COMMANDPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.COMMANDPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case InteractionPenalty:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableExplosionProtection:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.EXPLOSIONPROTECTION.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.EXPLOSIONPROTECTION.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case EnableFoodControl:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.FOODCONTROL.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.FOODCONTROL.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case FoodControlMinimumFood:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.FOODCONTROLMIN.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.FOODCONTROLMIN.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case FoodControlMaximumFood:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.FOODCONTROLMAX.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.FOODCONTROLMAX.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PrisonersRecieveMessages:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.RECIEVEMESSAGES.getPath(), OldSettings.getGlobalBoolean(global, s));
|
||||
pl.debug(Settings.RECIEVEMESSAGES.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case UseMySQL:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set("storage.type", OldSettings.getGlobalBoolean(global, s) ? "mysql" : "sqlite");
|
||||
pl.debug(Settings.RECIEVEMESSAGES.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case MySQLConn:
|
||||
if(global.contains(s.getString())) {
|
||||
//jdbc:mysql://localhost:3306/minecraft
|
||||
String con = OldSettings.getGlobalString(global, s);
|
||||
String a = con.split("//")[1];
|
||||
//localhost 3306/minecraft
|
||||
String[] b1 = a.split(":");
|
||||
//3306 minecraft
|
||||
String[] b2 = b1[1].split("/");
|
||||
|
||||
c.set("storage.mysql.host", b1[0]);
|
||||
c.set("storage.mysql.port", b2[0]);
|
||||
c.set("storage.mysql.database", b2[1]);
|
||||
|
||||
pl.debug("storage.mysql <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case MySQLUsername:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set("storage.mysql.username", OldSettings.getGlobalString(global, s));
|
||||
pl.debug("storage.mysql.username <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case MySQLPassword:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set("storage.mysql.password", OldSettings.getGlobalString(global, s));
|
||||
pl.debug("storage.mysql.password <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case PricePerMinute:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILPAYPRICEPERMINUTE.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.JAILPAYPRICEPERMINUTE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
case PriceForInfiniteJail:
|
||||
if(global.contains(s.getString())) {
|
||||
c.set(Settings.JAILPAYPRICEINFINITE.getPath(), OldSettings.getGlobalInt(global, s));
|
||||
pl.debug(Settings.JAILPAYPRICEINFINITE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
case JailPayCurrency:
|
||||
if(global.contains(s.getString())) {
|
||||
Material mat = Material.getMaterial(OldSettings.getGlobalInt(global, s));
|
||||
if(mat != null) {
|
||||
c.set(Settings.JAILPAYITEM.getPath(), mat.toString().toLowerCase());
|
||||
pl.debug(Settings.JAILPAYPRICEINFINITE.getPath() + " <-- " + s.getString());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pl.saveConfig();
|
||||
pl.getLogger().info("Converted " + count + " old config value" + (count == 1 ? "" : "s") + ".");
|
||||
}
|
||||
|
||||
private void loadOldData() throws SQLException {
|
||||
OldInputOutput o = new OldInputOutput(pl, global);
|
||||
|
||||
o.LoadJails();
|
||||
o.LoadPrisoners();
|
||||
o.LoadCells();
|
||||
o.freeConnection();
|
||||
}
|
||||
|
||||
private void moveOldConfigs() throws IOException {
|
||||
FileUtils.moveFileToDirectory(new File(pl.getDataFolder(), "global.yml"), new File(pl.getDataFolder() + File.separator + "preJail3Data"), true);
|
||||
FileUtils.moveFileToDirectory(new File(pl.getDataFolder(), "jails.yml"), new File(pl.getDataFolder() + File.separator + "preJail3Data"), true);
|
||||
FileUtils.moveFileToDirectory(new File(pl.getDataFolder(), "jailLog.txt"), new File(pl.getDataFolder() + File.separator + "preJail3Data"), true);
|
||||
|
||||
File sqlite = new File(pl.getDataFolder(), "jail.sqlite");
|
||||
if(sqlite.exists()) {
|
||||
FileUtils.moveFileToDirectory(sqlite, new File(pl.getDataFolder() + File.separator + "oldData"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,239 +1,239 @@
|
||||
package com.graywolf336.jail.legacy;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
|
||||
public class OldInputOutput {
|
||||
private JailMain pl;
|
||||
private Connection connection;
|
||||
private YamlConfiguration global;
|
||||
|
||||
public OldInputOutput(JailMain plugin, YamlConfiguration global) {
|
||||
this.pl = plugin;
|
||||
this.global = global;
|
||||
}
|
||||
|
||||
public synchronized Connection getConnection() throws SQLException {
|
||||
if (connection == null) connection = createConnection();
|
||||
if(OldSettings.getGlobalBoolean(global, OldSetting.UseMySQL)) {
|
||||
if(!connection.isValid(10)) connection = createConnection();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
private Connection createConnection() {
|
||||
try {
|
||||
if (OldSettings.getGlobalBoolean(global, OldSetting.UseMySQL)) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
Connection ret = DriverManager.getConnection(OldSettings.getGlobalString(global, OldSetting.MySQLConn), OldSettings.getGlobalString(global, OldSetting.MySQLUsername), OldSettings.getGlobalString(global, OldSetting.MySQLPassword));
|
||||
ret.setAutoCommit(false);
|
||||
return ret;
|
||||
} else {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
Connection ret = DriverManager.getConnection("jdbc:sqlite:" + new File(pl.getDataFolder().getPath(), "jail.sqlite").getPath());
|
||||
ret.setAutoCommit(false);
|
||||
return ret;
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void freeConnection() throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
if(conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadJails() throws SQLException {
|
||||
PreparedStatement ps = getConnection().prepareStatement("SELECT * FROM jail_zones");
|
||||
ResultSet set = ps.executeQuery();
|
||||
while (set.next()) {
|
||||
String name = set.getString("name").toLowerCase();
|
||||
double X1 = set.getDouble("X1");
|
||||
double Y1 = set.getDouble("Y1");
|
||||
double Z1 = set.getDouble("Z1");
|
||||
double X2 = set.getDouble("X2");
|
||||
double Y2 = set.getDouble("Y2");
|
||||
double Z2 = set.getDouble("Z2");
|
||||
double teleX = set.getDouble("teleX");
|
||||
double teleY = set.getDouble("teleY");
|
||||
double teleZ = set.getDouble("teleZ");
|
||||
double freeX = set.getDouble("freeX");
|
||||
double freeY = set.getDouble("freeY");
|
||||
double freeZ = set.getDouble("freeZ");
|
||||
String teleWorld = set.getString("teleWorld");
|
||||
String freeWorld = set.getString("freeWorld");
|
||||
|
||||
Jail j = new Jail(pl, name);
|
||||
j.setWorld(teleWorld);
|
||||
j.setMaxPoint(new Location(pl.getServer().getWorld(teleWorld), X1, Y1, Z1));
|
||||
j.setMinPoint(new Location(pl.getServer().getWorld(teleWorld), X2, Y2, Z2));
|
||||
j.setTeleportIn(new Location(pl.getServer().getWorld(teleWorld), teleX, teleY, teleZ));
|
||||
j.setTeleportFree(new Location(pl.getServer().getWorld(freeWorld), freeX, freeY, freeZ));
|
||||
|
||||
pl.getJailManager().addJail(j, false);
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void LoadPrisoners() throws SQLException {
|
||||
if(pl.getJailManager().getJails().size() != 0) {
|
||||
PreparedStatement ps = getConnection().prepareStatement("SELECT * FROM jail_prisoners");
|
||||
ResultSet set = ps.executeQuery();
|
||||
while (set.next()) {
|
||||
Jail j = pl.getJailManager().getJail(set.getString("JailName"));
|
||||
String name = set.getString("PlayerName").toLowerCase();
|
||||
|
||||
String transferDest = set.getString("TransferDest");
|
||||
boolean transfer = false;
|
||||
if(!transferDest.isEmpty()) {
|
||||
j = pl.getJailManager().getJail(transferDest);
|
||||
transfer = true;
|
||||
}
|
||||
|
||||
//In the event the jail is null (jail didn't transfer or the prisoner was jailed offline and no jail specified
|
||||
if(j == null) {
|
||||
j = pl.getJailManager().getJails().iterator().next();
|
||||
}
|
||||
|
||||
Prisoner p = new Prisoner(pl.getServer().getOfflinePlayer(name).getUniqueId().toString(), name, set.getBoolean("muted"), (long) set.getInt("RemainTime"), set.getString("Jailer"), set.getString("reason"));
|
||||
p.setOfflinePending(set.getBoolean("Offline"));
|
||||
p.setToBeTransferred(transfer);
|
||||
|
||||
j.addPrisoner(p);
|
||||
//String permissions = set.getString("Permissions"); TODO
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
}else {
|
||||
pl.getLogger().warning("No prisoners were transferred from the old database since there aren't any jails defined.");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadCells() throws SQLException {
|
||||
Connection conn;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet set = null;
|
||||
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM jail_cells");
|
||||
set = ps.executeQuery();
|
||||
while (set.next()) {
|
||||
String jailname = set.getString("JailName");
|
||||
String teleport = set.getString("Teleport");
|
||||
String sign = set.getString("Sign");
|
||||
String chest = set.getString("Chest");
|
||||
String player = set.getString("Player");
|
||||
String name = set.getString("Name");
|
||||
|
||||
if(name.isEmpty()) {
|
||||
pl.getLogger().warning("We need a cell name in Jail 3.0, refusing to load a cell due to this.");
|
||||
}else if(jailname.isEmpty()) {
|
||||
pl.getLogger().warning("Refusing to load a cell (" + name + ") as it does not contain a reference to a valid Jail.");
|
||||
}else {
|
||||
Jail j = pl.getJailManager().getJail(jailname);
|
||||
|
||||
if(j == null) {
|
||||
pl.getLogger().warning("Refusing to load a cell (" + name + ") as it references a Jail which doesn't exist.");
|
||||
}else if(j.isValidCell(name)) {
|
||||
pl.getLogger().warning("Refusing to load a duplicate named cell, " + name + ", as another one exists with that same name.");
|
||||
} else {
|
||||
Cell c = new Cell(name);
|
||||
|
||||
if(!teleport.isEmpty()) {
|
||||
String[] l = teleport.split(",");
|
||||
c.setTeleport(new SimpleLocation(j.getWorldName(), l[0], l[1], l[2]));
|
||||
}else {
|
||||
pl.getLogger().warning("Cell " + c.getName() + " in " + j.getName() + " has an empty teleport spot, might be buggy.");
|
||||
}
|
||||
|
||||
if(!chest.isEmpty()) {
|
||||
String[] ch = chest.split(",");
|
||||
c.setChestLocation(new Location(j.getWorld(), Double.valueOf(ch[0]), Double.valueOf(ch[1]), Double.valueOf(ch[2])));
|
||||
}else {
|
||||
pl.getLogger().warning("Cell " + c.getName() + " in " + j.getName() + " has no chest.");
|
||||
}
|
||||
|
||||
if(!sign.isEmpty()) {
|
||||
for(String s : sign.split(";")) {
|
||||
pl.debug(s);
|
||||
String[] si = s.split(",");
|
||||
c.addSign(new SimpleLocation(j.getWorldName(), si[0], si[1], si[2]));
|
||||
}
|
||||
}
|
||||
|
||||
//Load the prisoner if he is a valid prisoner
|
||||
if(!player.isEmpty()) {
|
||||
Prisoner p = j.getPrisonerByLastKnownName(player);
|
||||
|
||||
if(p != null) {
|
||||
j.removePrisoner(p);
|
||||
c.setPrisoner(p);
|
||||
}
|
||||
}
|
||||
|
||||
j.addCell(c, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void DeleteZone(String z) throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM jail_zones WHERE name = ?");
|
||||
ps.setString(1, z);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void DeleteCell(int x, int y, int z) throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM jail_cells WHERE Teleport = ?");
|
||||
ps.setString(1, String.valueOf(x) + "," + String.valueOf(y) + "," + String.valueOf(z));
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void DeletePrisoner(String p) throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM jail_prisoners WHERE PlayerName = ?");
|
||||
ps.setString(1, p);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
ps.close();
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.legacy;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
|
||||
public class OldInputOutput {
|
||||
private JailMain pl;
|
||||
private Connection connection;
|
||||
private YamlConfiguration global;
|
||||
|
||||
public OldInputOutput(JailMain plugin, YamlConfiguration global) {
|
||||
this.pl = plugin;
|
||||
this.global = global;
|
||||
}
|
||||
|
||||
public synchronized Connection getConnection() throws SQLException {
|
||||
if (connection == null) connection = createConnection();
|
||||
if(OldSettings.getGlobalBoolean(global, OldSetting.UseMySQL)) {
|
||||
if(!connection.isValid(10)) connection = createConnection();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
private Connection createConnection() {
|
||||
try {
|
||||
if (OldSettings.getGlobalBoolean(global, OldSetting.UseMySQL)) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
Connection ret = DriverManager.getConnection(OldSettings.getGlobalString(global, OldSetting.MySQLConn), OldSettings.getGlobalString(global, OldSetting.MySQLUsername), OldSettings.getGlobalString(global, OldSetting.MySQLPassword));
|
||||
ret.setAutoCommit(false);
|
||||
return ret;
|
||||
} else {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
Connection ret = DriverManager.getConnection("jdbc:sqlite:" + new File(pl.getDataFolder().getPath(), "jail.sqlite").getPath());
|
||||
ret.setAutoCommit(false);
|
||||
return ret;
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void freeConnection() throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
if(conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadJails() throws SQLException {
|
||||
PreparedStatement ps = getConnection().prepareStatement("SELECT * FROM jail_zones");
|
||||
ResultSet set = ps.executeQuery();
|
||||
while (set.next()) {
|
||||
String name = set.getString("name").toLowerCase();
|
||||
double X1 = set.getDouble("X1");
|
||||
double Y1 = set.getDouble("Y1");
|
||||
double Z1 = set.getDouble("Z1");
|
||||
double X2 = set.getDouble("X2");
|
||||
double Y2 = set.getDouble("Y2");
|
||||
double Z2 = set.getDouble("Z2");
|
||||
double teleX = set.getDouble("teleX");
|
||||
double teleY = set.getDouble("teleY");
|
||||
double teleZ = set.getDouble("teleZ");
|
||||
double freeX = set.getDouble("freeX");
|
||||
double freeY = set.getDouble("freeY");
|
||||
double freeZ = set.getDouble("freeZ");
|
||||
String teleWorld = set.getString("teleWorld");
|
||||
String freeWorld = set.getString("freeWorld");
|
||||
|
||||
Jail j = new Jail(pl, name);
|
||||
j.setWorld(teleWorld);
|
||||
j.setMaxPoint(new Location(pl.getServer().getWorld(teleWorld), X1, Y1, Z1));
|
||||
j.setMinPoint(new Location(pl.getServer().getWorld(teleWorld), X2, Y2, Z2));
|
||||
j.setTeleportIn(new Location(pl.getServer().getWorld(teleWorld), teleX, teleY, teleZ));
|
||||
j.setTeleportFree(new Location(pl.getServer().getWorld(freeWorld), freeX, freeY, freeZ));
|
||||
|
||||
pl.getJailManager().addJail(j, false);
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void LoadPrisoners() throws SQLException {
|
||||
if(pl.getJailManager().getJails().size() != 0) {
|
||||
PreparedStatement ps = getConnection().prepareStatement("SELECT * FROM jail_prisoners");
|
||||
ResultSet set = ps.executeQuery();
|
||||
while (set.next()) {
|
||||
Jail j = pl.getJailManager().getJail(set.getString("JailName"));
|
||||
String name = set.getString("PlayerName").toLowerCase();
|
||||
|
||||
String transferDest = set.getString("TransferDest");
|
||||
boolean transfer = false;
|
||||
if(!transferDest.isEmpty()) {
|
||||
j = pl.getJailManager().getJail(transferDest);
|
||||
transfer = true;
|
||||
}
|
||||
|
||||
//In the event the jail is null (jail didn't transfer or the prisoner was jailed offline and no jail specified
|
||||
if(j == null) {
|
||||
j = pl.getJailManager().getJails().iterator().next();
|
||||
}
|
||||
|
||||
Prisoner p = new Prisoner(pl.getServer().getOfflinePlayer(name).getUniqueId().toString(), name, set.getBoolean("muted"), (long) set.getInt("RemainTime"), set.getString("Jailer"), set.getString("reason"));
|
||||
p.setOfflinePending(set.getBoolean("Offline"));
|
||||
p.setToBeTransferred(transfer);
|
||||
|
||||
j.addPrisoner(p);
|
||||
//String permissions = set.getString("Permissions"); TODO
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
}else {
|
||||
pl.getLogger().warning("No prisoners were transferred from the old database since there aren't any jails defined.");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadCells() throws SQLException {
|
||||
Connection conn;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet set = null;
|
||||
|
||||
conn = getConnection();
|
||||
ps = conn.prepareStatement("SELECT * FROM jail_cells");
|
||||
set = ps.executeQuery();
|
||||
while (set.next()) {
|
||||
String jailname = set.getString("JailName");
|
||||
String teleport = set.getString("Teleport");
|
||||
String sign = set.getString("Sign");
|
||||
String chest = set.getString("Chest");
|
||||
String player = set.getString("Player");
|
||||
String name = set.getString("Name");
|
||||
|
||||
if(name.isEmpty()) {
|
||||
pl.getLogger().warning("We need a cell name in Jail 3.0, refusing to load a cell due to this.");
|
||||
}else if(jailname.isEmpty()) {
|
||||
pl.getLogger().warning("Refusing to load a cell (" + name + ") as it does not contain a reference to a valid Jail.");
|
||||
}else {
|
||||
Jail j = pl.getJailManager().getJail(jailname);
|
||||
|
||||
if(j == null) {
|
||||
pl.getLogger().warning("Refusing to load a cell (" + name + ") as it references a Jail which doesn't exist.");
|
||||
}else if(j.isValidCell(name)) {
|
||||
pl.getLogger().warning("Refusing to load a duplicate named cell, " + name + ", as another one exists with that same name.");
|
||||
} else {
|
||||
Cell c = new Cell(name);
|
||||
|
||||
if(!teleport.isEmpty()) {
|
||||
String[] l = teleport.split(",");
|
||||
c.setTeleport(new SimpleLocation(j.getWorldName(), l[0], l[1], l[2]));
|
||||
}else {
|
||||
pl.getLogger().warning("Cell " + c.getName() + " in " + j.getName() + " has an empty teleport spot, might be buggy.");
|
||||
}
|
||||
|
||||
if(!chest.isEmpty()) {
|
||||
String[] ch = chest.split(",");
|
||||
c.setChestLocation(new Location(j.getWorld(), Double.valueOf(ch[0]), Double.valueOf(ch[1]), Double.valueOf(ch[2])));
|
||||
}else {
|
||||
pl.getLogger().warning("Cell " + c.getName() + " in " + j.getName() + " has no chest.");
|
||||
}
|
||||
|
||||
if(!sign.isEmpty()) {
|
||||
for(String s : sign.split(";")) {
|
||||
pl.debug(s);
|
||||
String[] si = s.split(",");
|
||||
c.addSign(new SimpleLocation(j.getWorldName(), si[0], si[1], si[2]));
|
||||
}
|
||||
}
|
||||
|
||||
//Load the prisoner if he is a valid prisoner
|
||||
if(!player.isEmpty()) {
|
||||
Prisoner p = j.getPrisonerByLastKnownName(player);
|
||||
|
||||
if(p != null) {
|
||||
j.removePrisoner(p);
|
||||
c.setPrisoner(p);
|
||||
}
|
||||
}
|
||||
|
||||
j.addCell(c, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set.close();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void DeleteZone(String z) throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM jail_zones WHERE name = ?");
|
||||
ps.setString(1, z);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void DeleteCell(int x, int y, int z) throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM jail_cells WHERE Teleport = ?");
|
||||
ps.setString(1, String.valueOf(x) + "," + String.valueOf(y) + "," + String.valueOf(z));
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
ps.close();
|
||||
}
|
||||
|
||||
public void DeletePrisoner(String p) throws SQLException {
|
||||
Connection conn = getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("DELETE FROM jail_prisoners WHERE PlayerName = ?");
|
||||
ps.setString(1, p);
|
||||
ps.executeUpdate();
|
||||
conn.commit();
|
||||
|
||||
ps.close();
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,33 @@
|
||||
package com.graywolf336.jail.legacy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class OldSettings {
|
||||
|
||||
public static Object getGlobalProperty(YamlConfiguration config, OldSetting setting) {
|
||||
Object property = config.get(setting.getString());
|
||||
if (property == null) {
|
||||
property = setting.getDefault();
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
public static Boolean getGlobalBoolean(YamlConfiguration config, OldSetting setting) {
|
||||
return (Boolean) getGlobalProperty(config, setting);
|
||||
}
|
||||
|
||||
public static Integer getGlobalInt(YamlConfiguration config, OldSetting setting) {
|
||||
return (Integer) getGlobalProperty(config, setting);
|
||||
}
|
||||
|
||||
public static String getGlobalString(YamlConfiguration config, OldSetting setting) {
|
||||
return (String) getGlobalProperty(config, setting);
|
||||
}
|
||||
|
||||
public static List<?> getGlobalList(YamlConfiguration config, OldSetting setting) {
|
||||
return (List<?>) getGlobalProperty(config, setting);
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.legacy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class OldSettings {
|
||||
|
||||
public static Object getGlobalProperty(YamlConfiguration config, OldSetting setting) {
|
||||
Object property = config.get(setting.getString());
|
||||
if (property == null) {
|
||||
property = setting.getDefault();
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
public static Boolean getGlobalBoolean(YamlConfiguration config, OldSetting setting) {
|
||||
return (Boolean) getGlobalProperty(config, setting);
|
||||
}
|
||||
|
||||
public static Integer getGlobalInt(YamlConfiguration config, OldSetting setting) {
|
||||
return (Integer) getGlobalProperty(config, setting);
|
||||
}
|
||||
|
||||
public static String getGlobalString(YamlConfiguration config, OldSetting setting) {
|
||||
return (String) getGlobalProperty(config, setting);
|
||||
}
|
||||
|
||||
public static List<?> getGlobalList(YamlConfiguration config, OldSetting setting) {
|
||||
return (List<?>) getGlobalProperty(config, setting);
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,73 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.beans.CachePrisoner;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
|
||||
import com.graywolf336.jail.events.PrisonerJailedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerReleasedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerTransferredEvent;
|
||||
|
||||
public class CacheListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public CacheListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void joinListener(PlayerJoinEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
|
||||
|
||||
pl.getJailManager().addCacheObject(new CachePrisoner(j, p));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void leaveListener(PlayerQuitEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void kickListener(PlayerKickEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void jailListener(PrisonerJailedEvent event) {
|
||||
pl.getJailManager().addCacheObject(new CachePrisoner(event.getJail(), event.getPrisoner()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void releaseListener(PrisonerReleasedEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void beforeTransferringListener(PrePrisonerTransferredEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void transferListener(PrisonerTransferredEvent event) {
|
||||
pl.getJailManager().addCacheObject(new CachePrisoner(event.getTargetJail(), event.getPrisoner()));
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.beans.CachePrisoner;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.events.PrePrisonerTransferredEvent;
|
||||
import com.graywolf336.jail.events.PrisonerJailedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerReleasedEvent;
|
||||
import com.graywolf336.jail.events.PrisonerTransferredEvent;
|
||||
|
||||
public class CacheListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public CacheListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void joinListener(PlayerJoinEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
|
||||
|
||||
pl.getJailManager().addCacheObject(new CachePrisoner(j, p));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void leaveListener(PlayerQuitEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void kickListener(PlayerKickEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void jailListener(PrisonerJailedEvent event) {
|
||||
pl.getJailManager().addCacheObject(new CachePrisoner(event.getJail(), event.getPrisoner()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void releaseListener(PrisonerReleasedEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void beforeTransferringListener(PrePrisonerTransferredEvent event) {
|
||||
if(pl.getJailManager().inCache(event.getPlayer().getUniqueId())) {
|
||||
pl.getJailManager().removeCacheObject(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void transferListener(PrisonerTransferredEvent event) {
|
||||
pl.getJailManager().addCacheObject(new CachePrisoner(event.getTargetJail(), event.getPrisoner()));
|
||||
}
|
||||
}
|
||||
|
@ -1,112 +1,112 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
|
||||
public class HandCuffListener implements Listener {
|
||||
private JailMain pl;
|
||||
private HashMap<String, Location> tos;
|
||||
|
||||
public HandCuffListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.tos = new HashMap<String, Location>();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
to.setPitch(event.getTo().getPitch());
|
||||
to.setYaw(event.getTo().getYaw());
|
||||
|
||||
tos.put(event.getPlayer().getName(), to);
|
||||
event.getPlayer().teleport(to);
|
||||
|
||||
if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
|
||||
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if(event.getTo() != tos.get(event.getPlayer().getName())) {
|
||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
to.setPitch(event.getTo().getPitch());
|
||||
to.setYaw(event.getTo().getYaw());
|
||||
|
||||
tos.put(event.getPlayer().getName(), to);
|
||||
event.getPlayer().teleport(to);
|
||||
|
||||
if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
|
||||
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void playerChat(AsyncPlayerChatEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if(!event.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void blockBreak(BlockBreakEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to break blocks!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void blockPlace(BlockPlaceEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to place blocks!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preCommands(PlayerCommandPreprocessEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if(!event.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||
if(!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to use commands!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
|
||||
public class HandCuffListener implements Listener {
|
||||
private JailMain pl;
|
||||
private HashMap<String, Location> tos;
|
||||
|
||||
public HandCuffListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.tos = new HashMap<String, Location>();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
to.setPitch(event.getTo().getPitch());
|
||||
to.setYaw(event.getTo().getYaw());
|
||||
|
||||
tos.put(event.getPlayer().getName(), to);
|
||||
event.getPlayer().teleport(to);
|
||||
|
||||
if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
|
||||
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if(event.getTo() != tos.get(event.getPlayer().getName())) {
|
||||
Location to = pl.getHandCuffManager().getLocation(event.getPlayer().getUniqueId());
|
||||
to.setPitch(event.getTo().getPitch());
|
||||
to.setYaw(event.getTo().getYaw());
|
||||
|
||||
tos.put(event.getPlayer().getName(), to);
|
||||
event.getPlayer().teleport(to);
|
||||
|
||||
if(System.currentTimeMillis() >= pl.getHandCuffManager().getNextMessageTime(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and cant move!");
|
||||
pl.getHandCuffManager().updateNextTime(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void playerChat(AsyncPlayerChatEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if(!event.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to talk!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void blockBreak(BlockBreakEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to break blocks!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void blockPlace(BlockPlaceEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to place blocks!");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preCommands(PlayerCommandPreprocessEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
if (pl.getHandCuffManager().isHandCuffed(event.getPlayer().getUniqueId())) {
|
||||
if(!event.getPlayer().hasPermission("jail.command.handcuff")) {
|
||||
if(!event.getMessage().startsWith("/r") || !event.getMessage().startsWith("/reply")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "You are handcuffed and aren't allowed to use commands!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,39 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
|
||||
public class JailingListener implements Listener {
|
||||
private JailMain pl;
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public JailingListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.dateFormat = new SimpleDateFormat(pl.getJailIO().getLanguageString(LangString.TIMEFORMAT));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preJailingListener(PrePrisonerJailedEvent event) {
|
||||
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
|
||||
event.getPrisoner().getLastKnownName(),
|
||||
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
||||
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preJailingListener(PrePrisonerJailedByJailStickEvent event) {
|
||||
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
|
||||
event.getPrisoner().getLastKnownName(),
|
||||
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
||||
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedEvent;
|
||||
|
||||
public class JailingListener implements Listener {
|
||||
private JailMain pl;
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public JailingListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
this.dateFormat = new SimpleDateFormat(pl.getJailIO().getLanguageString(LangString.TIMEFORMAT));
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preJailingListener(PrePrisonerJailedEvent event) {
|
||||
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
|
||||
event.getPrisoner().getLastKnownName(),
|
||||
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
||||
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void preJailingListener(PrePrisonerJailedByJailStickEvent event) {
|
||||
pl.getJailIO().addRecordEntry(event.getPrisoner().getUUID().toString(),
|
||||
event.getPrisoner().getLastKnownName(),
|
||||
event.getPrisoner().getJailer(), dateFormat.format(new Date()),
|
||||
event.getPrisoner().getRemainingTimeInMinutes(), event.getPrisoner().getReason());
|
||||
}
|
||||
}
|
||||
|
@ -1,250 +1,250 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
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.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.Stick;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public PlayerListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void jailOrCellCreation(PlayerInteractEvent event) {
|
||||
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player p = event.getPlayer();
|
||||
Location loc = event.getClickedBlock() == null ? p.getLocation() : event.getClickedBlock().getLocation();
|
||||
JailManager jm = pl.getJailManager();
|
||||
|
||||
if(p.getItemInHand().isSimilar(Util.getWand())) {
|
||||
if(jm.isCreatingSomething(p.getName())) {
|
||||
if(jm.isCreatingAJail(p.getName())) {
|
||||
pl.debug("Stepping into creating a jail.");
|
||||
jm.getJailCreationSteps().step(jm, p, jm.getJailCreationPlayer(p.getName()), loc);
|
||||
}else if(jm.isCreatingACell(p.getName())) {
|
||||
pl.debug("Stepping into creating a cell.");
|
||||
jm.getCellCreationSteps().step(jm, p, jm.getCellCreationPlayer(p.getName()), loc);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void chatting(AsyncPlayerChatEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
if(pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).isMuted()) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(pl.getJailIO().getLanguageString(LangString.MUTED));
|
||||
}
|
||||
}
|
||||
|
||||
//If the config has receive messages set to false, let's remove all the prisoners
|
||||
//from getting the chat messages.
|
||||
if(!pl.getConfig().getBoolean(Settings.RECIEVEMESSAGES.getPath())) {
|
||||
if(pl.inDebug()) pl.getLogger().info("Debug - There are " + event.getRecipients().size() + " players getting the message before.");
|
||||
Set<Player> rec = new HashSet<Player>(event.getRecipients());
|
||||
|
||||
for(Jail j : pl.getJailManager().getJails())
|
||||
for(Prisoner p : j.getAllPrisoners().values())
|
||||
rec.remove(pl.getServer().getPlayer(p.getUUID()));
|
||||
|
||||
event.getRecipients().clear();
|
||||
event.getRecipients().addAll(rec);
|
||||
if(pl.inDebug()) pl.getLogger().info("Debug - There are now " + event.getRecipients().size() + " players getting the message.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void checkForOfflineJailStuff(PlayerJoinEvent event) {
|
||||
//Let's check if the player is jailed
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the prisoner object
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
|
||||
//update their last known username when they login
|
||||
p.setLastKnownName(event.getPlayer().getName());
|
||||
|
||||
//Check if they're offline pending, as if this is true then they were jailed offline
|
||||
if(p.isOfflinePending()) {
|
||||
if(p.getRemainingTime() == 0L) {
|
||||
//If their remaining time is 0, let's unjail them
|
||||
pl.getPrisonerManager().releasePrisoner(event.getPlayer(), p);
|
||||
}else if(p.isToBeTransferred()) {
|
||||
Cell c = j.getCellPrisonerIsIn(event.getPlayer().getUniqueId());
|
||||
|
||||
//If the player is not jailed in a cell, teleport them to the jail's in
|
||||
if(c == null) {
|
||||
p.setTeleporting(true);
|
||||
event.getPlayer().teleport(j.getTeleportIn());
|
||||
p.setTeleporting(false);
|
||||
}else {
|
||||
//If they are in a cell, teleport them into that cell
|
||||
p.setTeleporting(true);
|
||||
event.getPlayer().teleport(c.getTeleport());
|
||||
p.setTeleporting(false);
|
||||
}
|
||||
|
||||
p.setToBeTransferred(false);
|
||||
} else {
|
||||
//Their remaining time isn't 0 so let's proceed with jailing of the prisoner
|
||||
pl.getPrisonerManager().jailPlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
//Add the scoreboard to them if it is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
pl.getScoreBoardManager().addScoreBoard(event.getPlayer(), p);
|
||||
}
|
||||
|
||||
//if we are ignoring a prisoner's sleeping state, then let's set that
|
||||
if(pl.getConfig().getBoolean(Settings.IGNORESLEEPINGSTATE.getPath())) {
|
||||
event.getPlayer().setSleepingIgnored(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleGoingOffline(PlayerQuitEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Remove the scoreboard to them if it is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
pl.getScoreBoardManager().removeScoreBoard(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void handleGettingKicked(PlayerKickEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Remove the scoreboard to them if it is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
pl.getScoreBoardManager().removeScoreBoard(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void foodControl(FoodLevelChangeEvent event) {
|
||||
if(pl.getConfig().getBoolean(Settings.FOODCONTROL.getPath())) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getEntity().getUniqueId())) {
|
||||
int min = pl.getConfig().getInt(Settings.FOODCONTROLMIN.getPath());
|
||||
int max = pl.getConfig().getInt(Settings.FOODCONTROLMAX.getPath());
|
||||
|
||||
if (event.getFoodLevel() < min) {
|
||||
event.setFoodLevel(min);
|
||||
}else {
|
||||
event.setFoodLevel(max);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
|
||||
if(j.isJailedInACell(event.getPlayer().getUniqueId())) {
|
||||
event.setRespawnLocation(j.getCellPrisonerIsIn(event.getPlayer().getUniqueId()).getTeleport());
|
||||
}else {
|
||||
event.setRespawnLocation(j.getTeleportIn());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void jailStickHandling(EntityDamageByEntityEvent event) {
|
||||
//If the damager and the entity getting damage is not a player,
|
||||
//we don't want to handle it in this method
|
||||
if(!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Player)) return;
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if(pl.getJailStickManager().isUsingJailStick(attacker)) {
|
||||
if(pl.getJailStickManager().isValidStick(attacker.getItemInHand().getType())) {
|
||||
if(attacker.hasPermission("jail.usejailstick." + attacker.getItemInHand().getType().toString().toLowerCase())) {
|
||||
//The person the attacker is trying to jail stick is already jailed, don't handle that
|
||||
if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ALREADYJAILED, player.getName()));
|
||||
}else {
|
||||
if(player.hasPermission("jail.cantbejailed")) {
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANTBEJAILED));
|
||||
}else {
|
||||
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
|
||||
|
||||
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
|
||||
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
|
||||
s.getTime(), attacker.getName(), s.getReason());
|
||||
|
||||
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
|
||||
pl.getJailManager().getJail(s.getJail()), null, p, player, attacker.getName(), s);
|
||||
|
||||
pl.getServer().getPluginManager().callEvent(jEvent);
|
||||
|
||||
if(jEvent.isCancelled()) {
|
||||
if(jEvent.getCancelledMessage().isEmpty())
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, player.getName()));
|
||||
else
|
||||
attacker.sendMessage(jEvent.getCancelledMessage());
|
||||
}else {
|
||||
//recall data from the event
|
||||
Jail j = jEvent.getJail();
|
||||
Cell c = jEvent.getCell();
|
||||
p = jEvent.getPrisoner();
|
||||
player = jEvent.getPlayer();
|
||||
|
||||
//Player is not online
|
||||
if(player == null) {
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.OFFLINEJAIL,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ONLINEJAIL,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}
|
||||
|
||||
try {
|
||||
pl.getPrisonerManager().prepareJail(j, c, player, p);
|
||||
} catch (Exception e) {
|
||||
attacker.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
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.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.Stick;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
import com.graywolf336.jail.events.PrePrisonerJailedByJailStickEvent;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public PlayerListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void jailOrCellCreation(PlayerInteractEvent event) {
|
||||
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Player p = event.getPlayer();
|
||||
Location loc = event.getClickedBlock() == null ? p.getLocation() : event.getClickedBlock().getLocation();
|
||||
JailManager jm = pl.getJailManager();
|
||||
|
||||
if(p.getItemInHand().isSimilar(Util.getWand())) {
|
||||
if(jm.isCreatingSomething(p.getName())) {
|
||||
if(jm.isCreatingAJail(p.getName())) {
|
||||
pl.debug("Stepping into creating a jail.");
|
||||
jm.getJailCreationSteps().step(jm, p, jm.getJailCreationPlayer(p.getName()), loc);
|
||||
}else if(jm.isCreatingACell(p.getName())) {
|
||||
pl.debug("Stepping into creating a cell.");
|
||||
jm.getCellCreationSteps().step(jm, p, jm.getCellCreationPlayer(p.getName()), loc);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void chatting(AsyncPlayerChatEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
if(pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).isMuted()) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(pl.getJailIO().getLanguageString(LangString.MUTED));
|
||||
}
|
||||
}
|
||||
|
||||
//If the config has receive messages set to false, let's remove all the prisoners
|
||||
//from getting the chat messages.
|
||||
if(!pl.getConfig().getBoolean(Settings.RECIEVEMESSAGES.getPath())) {
|
||||
if(pl.inDebug()) pl.getLogger().info("Debug - There are " + event.getRecipients().size() + " players getting the message before.");
|
||||
Set<Player> rec = new HashSet<Player>(event.getRecipients());
|
||||
|
||||
for(Jail j : pl.getJailManager().getJails())
|
||||
for(Prisoner p : j.getAllPrisoners().values())
|
||||
rec.remove(pl.getServer().getPlayer(p.getUUID()));
|
||||
|
||||
event.getRecipients().clear();
|
||||
event.getRecipients().addAll(rec);
|
||||
if(pl.inDebug()) pl.getLogger().info("Debug - There are now " + event.getRecipients().size() + " players getting the message.");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void checkForOfflineJailStuff(PlayerJoinEvent event) {
|
||||
//Let's check if the player is jailed
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the prisoner object
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
Prisoner p = j.getPrisoner(event.getPlayer().getUniqueId());
|
||||
//update their last known username when they login
|
||||
p.setLastKnownName(event.getPlayer().getName());
|
||||
|
||||
//Check if they're offline pending, as if this is true then they were jailed offline
|
||||
if(p.isOfflinePending()) {
|
||||
if(p.getRemainingTime() == 0L) {
|
||||
//If their remaining time is 0, let's unjail them
|
||||
pl.getPrisonerManager().releasePrisoner(event.getPlayer(), p);
|
||||
}else if(p.isToBeTransferred()) {
|
||||
Cell c = j.getCellPrisonerIsIn(event.getPlayer().getUniqueId());
|
||||
|
||||
//If the player is not jailed in a cell, teleport them to the jail's in
|
||||
if(c == null) {
|
||||
p.setTeleporting(true);
|
||||
event.getPlayer().teleport(j.getTeleportIn());
|
||||
p.setTeleporting(false);
|
||||
}else {
|
||||
//If they are in a cell, teleport them into that cell
|
||||
p.setTeleporting(true);
|
||||
event.getPlayer().teleport(c.getTeleport());
|
||||
p.setTeleporting(false);
|
||||
}
|
||||
|
||||
p.setToBeTransferred(false);
|
||||
} else {
|
||||
//Their remaining time isn't 0 so let's proceed with jailing of the prisoner
|
||||
pl.getPrisonerManager().jailPlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
//Add the scoreboard to them if it is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
pl.getScoreBoardManager().addScoreBoard(event.getPlayer(), p);
|
||||
}
|
||||
|
||||
//if we are ignoring a prisoner's sleeping state, then let's set that
|
||||
if(pl.getConfig().getBoolean(Settings.IGNORESLEEPINGSTATE.getPath())) {
|
||||
event.getPlayer().setSleepingIgnored(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleGoingOffline(PlayerQuitEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Remove the scoreboard to them if it is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
pl.getScoreBoardManager().removeScoreBoard(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void handleGettingKicked(PlayerKickEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Remove the scoreboard to them if it is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.SCOREBOARDENABLED.getPath())) {
|
||||
pl.getScoreBoardManager().removeScoreBoard(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void foodControl(FoodLevelChangeEvent event) {
|
||||
if(pl.getConfig().getBoolean(Settings.FOODCONTROL.getPath())) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getEntity().getUniqueId())) {
|
||||
int min = pl.getConfig().getInt(Settings.FOODCONTROLMIN.getPath());
|
||||
int max = pl.getConfig().getInt(Settings.FOODCONTROLMAX.getPath());
|
||||
|
||||
if (event.getFoodLevel() < min) {
|
||||
event.setFoodLevel(min);
|
||||
}else {
|
||||
event.setFoodLevel(max);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId());
|
||||
|
||||
if(j.isJailedInACell(event.getPlayer().getUniqueId())) {
|
||||
event.setRespawnLocation(j.getCellPrisonerIsIn(event.getPlayer().getUniqueId()).getTeleport());
|
||||
}else {
|
||||
event.setRespawnLocation(j.getTeleportIn());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void jailStickHandling(EntityDamageByEntityEvent event) {
|
||||
//If the damager and the entity getting damage is not a player,
|
||||
//we don't want to handle it in this method
|
||||
if(!(event.getDamager() instanceof Player) || !(event.getEntity() instanceof Player)) return;
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if(pl.getJailStickManager().isUsingJailStick(attacker)) {
|
||||
if(pl.getJailStickManager().isValidStick(attacker.getItemInHand().getType())) {
|
||||
if(attacker.hasPermission("jail.usejailstick." + attacker.getItemInHand().getType().toString().toLowerCase())) {
|
||||
//The person the attacker is trying to jail stick is already jailed, don't handle that
|
||||
if(pl.getJailManager().isPlayerJailed(player.getUniqueId())) {
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ALREADYJAILED, player.getName()));
|
||||
}else {
|
||||
if(player.hasPermission("jail.cantbejailed")) {
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANTBEJAILED));
|
||||
}else {
|
||||
Stick s = pl.getJailStickManager().getStick(attacker.getItemInHand().getType());
|
||||
|
||||
Prisoner p = new Prisoner(player.getUniqueId().toString(), player.getName(),
|
||||
pl.getConfig().getBoolean(Settings.AUTOMATICMUTE.getPath()),
|
||||
s.getTime(), attacker.getName(), s.getReason());
|
||||
|
||||
PrePrisonerJailedByJailStickEvent jEvent = new PrePrisonerJailedByJailStickEvent(
|
||||
pl.getJailManager().getJail(s.getJail()), null, p, player, attacker.getName(), s);
|
||||
|
||||
pl.getServer().getPluginManager().callEvent(jEvent);
|
||||
|
||||
if(jEvent.isCancelled()) {
|
||||
if(jEvent.getCancelledMessage().isEmpty())
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.CANCELLEDBYANOTHERPLUGIN, player.getName()));
|
||||
else
|
||||
attacker.sendMessage(jEvent.getCancelledMessage());
|
||||
}else {
|
||||
//recall data from the event
|
||||
Jail j = jEvent.getJail();
|
||||
Cell c = jEvent.getCell();
|
||||
p = jEvent.getPrisoner();
|
||||
player = jEvent.getPlayer();
|
||||
|
||||
//Player is not online
|
||||
if(player == null) {
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.OFFLINEJAIL,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}else {
|
||||
//Player *is* online
|
||||
attacker.sendMessage(pl.getJailIO().getLanguageString(LangString.ONLINEJAIL,
|
||||
new String[] { p.getLastKnownName(), String.valueOf(p.getRemainingTimeInMinutes()) }));
|
||||
}
|
||||
|
||||
try {
|
||||
pl.getPrisonerManager().prepareJail(j, c, player, p);
|
||||
} catch (Exception e) {
|
||||
attacker.sendMessage(ChatColor.RED + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,319 +1,319 @@
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class ProtectionListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public ProtectionListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void protectionBlockBreaking(BlockBreakEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.BLOCKBREAKPROTECTION.getPath())) {
|
||||
//Let's check if the player is jailed, otherwise the other listener
|
||||
//in the BlockListener class will take care of protecting inside
|
||||
//of the jails.
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the breaking whitelist, check if the current item is in there
|
||||
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()),
|
||||
event.getBlock().getType().toString().toLowerCase())) {
|
||||
//As our Util.getTime throws an exception when the time is in an
|
||||
//incorrect format, we catch the exception and don't add any time
|
||||
//as a fail safe, don't want us to go crazy adding tons of time.
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.BLOCKBREAKPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.BLOCKBREAKING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.BLOCKBREAKING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Block break penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the event from happening, as the block wasn't in the whitelist
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void protectionBlockPlacing(BlockPlaceEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.BLOCKPLACEPROTECTION.getPath())) {
|
||||
//Let's check if the player is jailed, otherwise the other listener
|
||||
//in the BlockListener class will take care of protecting inside
|
||||
//of the jails.
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the placing whitelist, check if the current item is in there
|
||||
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()),
|
||||
event.getBlock().getType().toString().toLowerCase())) {
|
||||
//As our Util.getTime throws an exception when the time is in an
|
||||
//incorrect format, we catch the exception and don't add any time
|
||||
//as a fail safe, don't want us to go crazy adding tons of time.
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.BLOCKPLACEPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.BLOCKPLACING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.BLOCKPLACING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Block place penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the event from happening, as the block wasn't in the whitelist
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void commandProtection(PlayerCommandPreprocessEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.COMMANDPROTECTION.getPath())) {
|
||||
//Let's check if this player is jailed, if so then we continue
|
||||
//otherwise we don't care about commands in here
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
boolean match = false;
|
||||
|
||||
for(String whited : pl.getConfig().getStringList(Settings.COMMANDWHITELIST.getPath()))
|
||||
if(event.getMessage().toLowerCase().startsWith(whited.toLowerCase()))
|
||||
match = true;
|
||||
|
||||
//If no match found in the whitelist, then let's block this command.
|
||||
if(!match) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.COMMANDPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.COMMAND));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.COMMAND) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Command Protection penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the command from happening, as it wasn't whitelisted
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void chestProtection(PlayerInteractEvent event) {
|
||||
//First thing is first, let's be sure the player we're dealing with is in jail
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Next, let's check if it is a chest and if they're in a cell
|
||||
//If they are in a cell and are opening a chest, then we check
|
||||
//the config to see if they can open the chests
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST) {
|
||||
//Let's get the cell the player is in, then check if it is null or not.
|
||||
if(pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId()).isJailedInACell(event.getPlayer().getUniqueId())) {
|
||||
if(pl.getConfig().getBoolean(Settings.PRISONEROPENCHEST.getPath())) {
|
||||
//The prisoner is in a cell, so let's check if it is a couple chest.
|
||||
Material bpos1 = event.getClickedBlock().getLocation().add(-1, 0, 0).getBlock().getType();
|
||||
Material bpos2 = event.getClickedBlock().getLocation().add(+1, 0, 0).getBlock().getType();
|
||||
Material bpos3 = event.getClickedBlock().getLocation().add(0, 0, -1).getBlock().getType();
|
||||
Material bpos4 = event.getClickedBlock().getLocation().add(0, 0, +1).getBlock().getType();
|
||||
|
||||
boolean pos1 = bpos1 == Material.CHEST || bpos1 == Material.TRAPPED_CHEST;
|
||||
boolean pos2 = bpos2 == Material.CHEST || bpos2 == Material.TRAPPED_CHEST;
|
||||
boolean pos3 = bpos3 == Material.CHEST || bpos3 == Material.TRAPPED_CHEST;
|
||||
boolean pos4 = bpos4 == Material.CHEST || bpos4 == Material.TRAPPED_CHEST;
|
||||
|
||||
if(pos1 || pos2 || pos3 || pos4) {
|
||||
//it is a double chest, so they're free to go!
|
||||
if(pl.inDebug()) event.getPlayer().sendMessage("[Jail Debug]: You're opening up a double chest.");
|
||||
}else {
|
||||
//it is not a double chest, so we won't be allowing it.
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
//the config has opening chests disabled
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
//The prisoner is not in a cell, so let's not allow it. IF we get feedback from people who
|
||||
//use the plugin, this might get removed or permission node might be added.
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOWEST)
|
||||
public void cropTramplingProtection(PlayerInteractEvent event) {
|
||||
//First thing is first, let's be sure the player we're dealing with is in jail
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Next, check if crap trampling protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.CROPTRAMPLINGPROTECTION.getPath())) {
|
||||
if(event.getAction() == Action.PHYSICAL && event.getClickedBlock().getType() == Material.SOIL) {
|
||||
if(pl.getJailManager().getJailFromLocation(event.getClickedBlock().getLocation()) != null) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.CROPTRAMPLINGPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.CROPTRAMPLING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.CROPTRAMPLING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Crop Trampling penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void interactionProtection(PlayerInteractEvent event) {
|
||||
//As the old version didn't do anything with Physical interactions, we won't either
|
||||
if (event.getAction() != Action.PHYSICAL) {
|
||||
//First thing is first, let's be sure the player we're dealing with is in jail
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
|
||||
//Let's check if they've interacted with a block
|
||||
if (event.getClickedBlock() != null) {
|
||||
//Get the interaction blacklist, check if the current block is in there
|
||||
//if it is, then let's take action
|
||||
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath()),
|
||||
event.getClickedBlock().getType().toString().toLowerCase())) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch(Exception e) {
|
||||
pl.getLogger().severe("Prevent Interaction with Blocks penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}else if (event.getPlayer().getItemInHand() != null) {
|
||||
//Otherwise let's check if they have something in hand
|
||||
//Get the interaction blacklist, check if the current item is in there
|
||||
//if it is, then let's take action
|
||||
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()),
|
||||
event.getClickedBlock().getType().toString().toLowerCase())) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch(Exception e) {
|
||||
pl.getLogger().severe("Prevent Interaction with Items penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.listeners;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
import com.graywolf336.jail.enums.Settings;
|
||||
|
||||
public class ProtectionListener implements Listener {
|
||||
private JailMain pl;
|
||||
|
||||
public ProtectionListener(JailMain plugin) {
|
||||
this.pl = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void protectionBlockBreaking(BlockBreakEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.BLOCKBREAKPROTECTION.getPath())) {
|
||||
//Let's check if the player is jailed, otherwise the other listener
|
||||
//in the BlockListener class will take care of protecting inside
|
||||
//of the jails.
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the breaking whitelist, check if the current item is in there
|
||||
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKBREAKWHITELIST.getPath()),
|
||||
event.getBlock().getType().toString().toLowerCase())) {
|
||||
//As our Util.getTime throws an exception when the time is in an
|
||||
//incorrect format, we catch the exception and don't add any time
|
||||
//as a fail safe, don't want us to go crazy adding tons of time.
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.BLOCKBREAKPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.BLOCKBREAKING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.BLOCKBREAKING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Block break penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the event from happening, as the block wasn't in the whitelist
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void protectionBlockPlacing(BlockPlaceEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.BLOCKPLACEPROTECTION.getPath())) {
|
||||
//Let's check if the player is jailed, otherwise the other listener
|
||||
//in the BlockListener class will take care of protecting inside
|
||||
//of the jails.
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Get the placing whitelist, check if the current item is in there
|
||||
if(!Util.isStringInsideList(pl.getConfig().getStringList(Settings.BLOCKPLACEWHITELIST.getPath()),
|
||||
event.getBlock().getType().toString().toLowerCase())) {
|
||||
//As our Util.getTime throws an exception when the time is in an
|
||||
//incorrect format, we catch the exception and don't add any time
|
||||
//as a fail safe, don't want us to go crazy adding tons of time.
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.BLOCKPLACEPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.BLOCKPLACING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.BLOCKPLACING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Block place penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the event from happening, as the block wasn't in the whitelist
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void commandProtection(PlayerCommandPreprocessEvent event) {
|
||||
//Before we check if the player is jailed, let's save a
|
||||
//tiny bit of resources and check if this protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.COMMANDPROTECTION.getPath())) {
|
||||
//Let's check if this player is jailed, if so then we continue
|
||||
//otherwise we don't care about commands in here
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
boolean match = false;
|
||||
|
||||
for(String whited : pl.getConfig().getStringList(Settings.COMMANDWHITELIST.getPath()))
|
||||
if(event.getMessage().toLowerCase().startsWith(whited.toLowerCase()))
|
||||
match = true;
|
||||
|
||||
//If no match found in the whitelist, then let's block this command.
|
||||
if(!match) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.COMMANDPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.COMMAND));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.COMMAND) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Command Protection penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
//Stop the command from happening, as it wasn't whitelisted
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOW)
|
||||
public void chestProtection(PlayerInteractEvent event) {
|
||||
//First thing is first, let's be sure the player we're dealing with is in jail
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Next, let's check if it is a chest and if they're in a cell
|
||||
//If they are in a cell and are opening a chest, then we check
|
||||
//the config to see if they can open the chests
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST) {
|
||||
//Let's get the cell the player is in, then check if it is null or not.
|
||||
if(pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getUniqueId()).isJailedInACell(event.getPlayer().getUniqueId())) {
|
||||
if(pl.getConfig().getBoolean(Settings.PRISONEROPENCHEST.getPath())) {
|
||||
//The prisoner is in a cell, so let's check if it is a couple chest.
|
||||
Material bpos1 = event.getClickedBlock().getLocation().add(-1, 0, 0).getBlock().getType();
|
||||
Material bpos2 = event.getClickedBlock().getLocation().add(+1, 0, 0).getBlock().getType();
|
||||
Material bpos3 = event.getClickedBlock().getLocation().add(0, 0, -1).getBlock().getType();
|
||||
Material bpos4 = event.getClickedBlock().getLocation().add(0, 0, +1).getBlock().getType();
|
||||
|
||||
boolean pos1 = bpos1 == Material.CHEST || bpos1 == Material.TRAPPED_CHEST;
|
||||
boolean pos2 = bpos2 == Material.CHEST || bpos2 == Material.TRAPPED_CHEST;
|
||||
boolean pos3 = bpos3 == Material.CHEST || bpos3 == Material.TRAPPED_CHEST;
|
||||
boolean pos4 = bpos4 == Material.CHEST || bpos4 == Material.TRAPPED_CHEST;
|
||||
|
||||
if(pos1 || pos2 || pos3 || pos4) {
|
||||
//it is a double chest, so they're free to go!
|
||||
if(pl.inDebug()) event.getPlayer().sendMessage("[Jail Debug]: You're opening up a double chest.");
|
||||
}else {
|
||||
//it is not a double chest, so we won't be allowing it.
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
//the config has opening chests disabled
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
//The prisoner is not in a cell, so let's not allow it. IF we get feedback from people who
|
||||
//use the plugin, this might get removed or permission node might be added.
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true, priority = EventPriority.LOWEST)
|
||||
public void cropTramplingProtection(PlayerInteractEvent event) {
|
||||
//First thing is first, let's be sure the player we're dealing with is in jail
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
//Next, check if crap trampling protection is enabled
|
||||
if(pl.getConfig().getBoolean(Settings.CROPTRAMPLINGPROTECTION.getPath())) {
|
||||
if(event.getAction() == Action.PHYSICAL && event.getClickedBlock().getType() == Material.SOIL) {
|
||||
if(pl.getJailManager().getJailFromLocation(event.getClickedBlock().getLocation()) != null) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.CROPTRAMPLINGPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.CROPTRAMPLING));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.CROPTRAMPLING) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch (Exception e) {
|
||||
pl.getLogger().severe("Crop Trampling penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
public void interactionProtection(PlayerInteractEvent event) {
|
||||
//As the old version didn't do anything with Physical interactions, we won't either
|
||||
if (event.getAction() != Action.PHYSICAL) {
|
||||
//First thing is first, let's be sure the player we're dealing with is in jail
|
||||
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getUniqueId())) {
|
||||
|
||||
//Let's check if they've interacted with a block
|
||||
if (event.getClickedBlock() != null) {
|
||||
//Get the interaction blacklist, check if the current block is in there
|
||||
//if it is, then let's take action
|
||||
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONBLOCKS.getPath()),
|
||||
event.getClickedBlock().getType().toString().toLowerCase())) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONBLOCKSPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.INTERACTIONBLOCKS) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch(Exception e) {
|
||||
pl.getLogger().severe("Prevent Interaction with Blocks penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}else if (event.getPlayer().getItemInHand() != null) {
|
||||
//Otherwise let's check if they have something in hand
|
||||
//Get the interaction blacklist, check if the current item is in there
|
||||
//if it is, then let's take action
|
||||
if(Util.isStringInsideList(pl.getConfig().getStringList(Settings.PREVENTINTERACTIONITEMS.getPath()),
|
||||
event.getClickedBlock().getType().toString().toLowerCase())) {
|
||||
try {
|
||||
long add = Util.getTime(pl.getConfig().getString(Settings.PREVENTINTERACTIONITEMSPENALTY.getPath()));
|
||||
pl.getJailManager().getPrisoner(event.getPlayer().getUniqueId()).addTime(add);
|
||||
|
||||
String msg = "";
|
||||
if(add == 0L) {
|
||||
//Generate the protection message, provide the method with one argument
|
||||
//which is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGENOPENALTY, pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS));
|
||||
}else {
|
||||
//Generate the protection message, provide the method with two arguments
|
||||
//First is the time in minutes and second is the thing we are protecting against
|
||||
msg = pl.getJailIO().getLanguageString(LangString.PROTECTIONMESSAGE,
|
||||
new String[] { String.valueOf(TimeUnit.MINUTES.convert(add, TimeUnit.MILLISECONDS)),
|
||||
pl.getJailIO().getLanguageString(LangString.INTERACTIONITEMS) });
|
||||
}
|
||||
|
||||
//Send the message
|
||||
event.getPlayer().sendMessage(msg);
|
||||
}catch(Exception e) {
|
||||
pl.getLogger().severe("Prevent Interaction with Items penalty's time is in the wrong format, please fix.");
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,157 +1,157 @@
|
||||
package com.graywolf336.jail.steps;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.CreationPlayer;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
|
||||
/**
|
||||
* Class for stepping a player through the Cell creation process, instance is stored in {@link JailManager}.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.1
|
||||
*/
|
||||
public class CellCreationSteps {
|
||||
|
||||
/** Sends the Cell Creation message for starting out. */
|
||||
public void startStepping(Player player){
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (tp) ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "First, you must select a teleport point for the cell! Move to the teleport point and then click anywhere with your wooden sword to set it.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
ItemStack wand = Util.getWand();
|
||||
if(player.getInventory().contains(wand)) {
|
||||
int i = player.getInventory().first(wand);
|
||||
if(i != -1) {
|
||||
player.getInventory().setItem(i, player.getItemInHand());
|
||||
player.setItemInHand(wand);
|
||||
}
|
||||
}else {
|
||||
player.getInventory().addItem(wand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the next step in the Cell Creation process that involves a location, null if no location is needed.
|
||||
*
|
||||
* @param jm The {@link JailManager} instance.
|
||||
* @param player The player who is doing the creating.
|
||||
* @param cp The {@link CreationPlayer} instance
|
||||
* @param location The location, null if none, being set.
|
||||
*/
|
||||
public void step(JailManager jm, Player player, CreationPlayer cp, Location location) {
|
||||
jm.getPlugin().debug("Stepping into step #" + cp.getStep());
|
||||
switch(cp.getStep()) {
|
||||
case 1:
|
||||
firstStep(jm, cp, player);
|
||||
break;
|
||||
case 2:
|
||||
secondStep(cp, player, location.getBlock());
|
||||
break;
|
||||
case 3:
|
||||
thirdStep(jm, cp, player, location.getBlock());
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over");
|
||||
jm.removeJailCreationPlayer(player.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the first step, which is setting the teleport in location. */
|
||||
private void firstStep(JailManager jm, CreationPlayer cp, Player player) {
|
||||
Vector v1 = jm.getJail(cp.getJailName()).getMinPoint().toVector().clone();
|
||||
Vector v2 = jm.getJail(cp.getJailName()).getMaxPoint().toVector().clone();
|
||||
Vector point = player.getLocation().toVector().clone();
|
||||
|
||||
if(Util.isInsideAB(point, v1, v2)) {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (signs) ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "Teleport point selected. Now select signs associated with this cell. You may select multiple signs. After you are done with the sign selection, right click on any non-sign block.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
cp.setTeleportIn(player.getLocation());
|
||||
cp.nextStep();
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "---------- Jail Cell Creation (tp) ----------");
|
||||
player.sendMessage(ChatColor.RED + "Teleport point NOT selected. Please make sure that you are setting the teleport point inside the Jail's corners.");
|
||||
player.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the second step, which is adding signs to the cell. */
|
||||
private void secondStep(CreationPlayer cp, Player player, Block block) {
|
||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
|
||||
cp.addSign(new SimpleLocation(block.getLocation()));
|
||||
player.sendMessage(ChatColor.GREEN + "Sign added, if you want to select another go ahead otherwise right click on any non-sign block.");
|
||||
}else {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (chest) ----------");
|
||||
player.sendMessage(ChatColor.GREEN + (cp.getSigns().size() != 0 ? "Sign selection completed. " : "") + "Now select a double chest associated with this cell. If there is no chest click on any non-chest block. (Please note that having no chest may result in players items being lost.)");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
cp.nextStep();
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the third step, which is adding a chest or select not to have a chest. */
|
||||
private void thirdStep(JailManager jm, CreationPlayer cp, Player player, Block block) {
|
||||
Material bpos1 = block.getLocation().add(-1, 0, 0).getBlock().getType();
|
||||
Material bpos2 = block.getLocation().add(+1, 0, 0).getBlock().getType();
|
||||
Material bpos3 = block.getLocation().add(0, 0, -1).getBlock().getType();
|
||||
Material bpos4 = block.getLocation().add(0, 0, +1).getBlock().getType();
|
||||
|
||||
boolean pos1 = bpos1 == Material.CHEST || bpos1 == Material.TRAPPED_CHEST;
|
||||
boolean pos2 = bpos2 == Material.CHEST || bpos2 == Material.TRAPPED_CHEST;
|
||||
boolean pos3 = bpos3 == Material.CHEST || bpos3 == Material.TRAPPED_CHEST;
|
||||
boolean pos4 = bpos4 == Material.CHEST || bpos4 == Material.TRAPPED_CHEST;
|
||||
|
||||
if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST) {
|
||||
if(pos1 || pos2 || pos3 || pos4) {
|
||||
cp.setChestLocation(block.getLocation());
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "Chest selected.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "---------- Jail Cell Creation (chest) ----------");
|
||||
player.sendMessage(ChatColor.RED + "Chest must be a double chest, chest not selected");
|
||||
player.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||
player.sendMessage(ChatColor.RED + "No chest selected.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
}
|
||||
|
||||
finalStep(jm, cp, player);
|
||||
}
|
||||
|
||||
private void finalStep(JailManager jm, CreationPlayer cp, Player player) {
|
||||
Jail j = jm.getJail(cp.getJailName());
|
||||
Cell c = new Cell(cp.getCellName());
|
||||
|
||||
c.addAllSigns(cp.getSigns());
|
||||
c.setTeleport(cp.getTeleportInSL());
|
||||
|
||||
if(cp.getChestLocation() != null)
|
||||
c.setChestLocation(cp.getChestLocation());
|
||||
|
||||
j.addCell(c, true);
|
||||
|
||||
jm.removeCellCreationPlayer(player.getName());
|
||||
jm.addCreatingCell(player.getName(), j.getName(), "cell_n" + (j.getCellCount() + 1));
|
||||
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "Cell created. Now select the teleport point of the next cell, which is going to be named '" + jm.getCellCreationPlayer(player.getName()).getCellName() + "'. If you wish to stop creating cells, type /jail stop.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.steps;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.CreationPlayer;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
|
||||
/**
|
||||
* Class for stepping a player through the Cell creation process, instance is stored in {@link JailManager}.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.0.1
|
||||
*/
|
||||
public class CellCreationSteps {
|
||||
|
||||
/** Sends the Cell Creation message for starting out. */
|
||||
public void startStepping(Player player){
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (tp) ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "First, you must select a teleport point for the cell! Move to the teleport point and then click anywhere with your wooden sword to set it.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
ItemStack wand = Util.getWand();
|
||||
if(player.getInventory().contains(wand)) {
|
||||
int i = player.getInventory().first(wand);
|
||||
if(i != -1) {
|
||||
player.getInventory().setItem(i, player.getItemInHand());
|
||||
player.setItemInHand(wand);
|
||||
}
|
||||
}else {
|
||||
player.getInventory().addItem(wand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the next step in the Cell Creation process that involves a location, null if no location is needed.
|
||||
*
|
||||
* @param jm The {@link JailManager} instance.
|
||||
* @param player The player who is doing the creating.
|
||||
* @param cp The {@link CreationPlayer} instance
|
||||
* @param location The location, null if none, being set.
|
||||
*/
|
||||
public void step(JailManager jm, Player player, CreationPlayer cp, Location location) {
|
||||
jm.getPlugin().debug("Stepping into step #" + cp.getStep());
|
||||
switch(cp.getStep()) {
|
||||
case 1:
|
||||
firstStep(jm, cp, player);
|
||||
break;
|
||||
case 2:
|
||||
secondStep(cp, player, location.getBlock());
|
||||
break;
|
||||
case 3:
|
||||
thirdStep(jm, cp, player, location.getBlock());
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over");
|
||||
jm.removeJailCreationPlayer(player.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the first step, which is setting the teleport in location. */
|
||||
private void firstStep(JailManager jm, CreationPlayer cp, Player player) {
|
||||
Vector v1 = jm.getJail(cp.getJailName()).getMinPoint().toVector().clone();
|
||||
Vector v2 = jm.getJail(cp.getJailName()).getMaxPoint().toVector().clone();
|
||||
Vector point = player.getLocation().toVector().clone();
|
||||
|
||||
if(Util.isInsideAB(point, v1, v2)) {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (signs) ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "Teleport point selected. Now select signs associated with this cell. You may select multiple signs. After you are done with the sign selection, right click on any non-sign block.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
cp.setTeleportIn(player.getLocation());
|
||||
cp.nextStep();
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "---------- Jail Cell Creation (tp) ----------");
|
||||
player.sendMessage(ChatColor.RED + "Teleport point NOT selected. Please make sure that you are setting the teleport point inside the Jail's corners.");
|
||||
player.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the second step, which is adding signs to the cell. */
|
||||
private void secondStep(CreationPlayer cp, Player player, Block block) {
|
||||
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
|
||||
cp.addSign(new SimpleLocation(block.getLocation()));
|
||||
player.sendMessage(ChatColor.GREEN + "Sign added, if you want to select another go ahead otherwise right click on any non-sign block.");
|
||||
}else {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation (chest) ----------");
|
||||
player.sendMessage(ChatColor.GREEN + (cp.getSigns().size() != 0 ? "Sign selection completed. " : "") + "Now select a double chest associated with this cell. If there is no chest click on any non-chest block. (Please note that having no chest may result in players items being lost.)");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
cp.nextStep();
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the third step, which is adding a chest or select not to have a chest. */
|
||||
private void thirdStep(JailManager jm, CreationPlayer cp, Player player, Block block) {
|
||||
Material bpos1 = block.getLocation().add(-1, 0, 0).getBlock().getType();
|
||||
Material bpos2 = block.getLocation().add(+1, 0, 0).getBlock().getType();
|
||||
Material bpos3 = block.getLocation().add(0, 0, -1).getBlock().getType();
|
||||
Material bpos4 = block.getLocation().add(0, 0, +1).getBlock().getType();
|
||||
|
||||
boolean pos1 = bpos1 == Material.CHEST || bpos1 == Material.TRAPPED_CHEST;
|
||||
boolean pos2 = bpos2 == Material.CHEST || bpos2 == Material.TRAPPED_CHEST;
|
||||
boolean pos3 = bpos3 == Material.CHEST || bpos3 == Material.TRAPPED_CHEST;
|
||||
boolean pos4 = bpos4 == Material.CHEST || bpos4 == Material.TRAPPED_CHEST;
|
||||
|
||||
if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST) {
|
||||
if(pos1 || pos2 || pos3 || pos4) {
|
||||
cp.setChestLocation(block.getLocation());
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "Chest selected.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
}else {
|
||||
player.sendMessage(ChatColor.RED + "---------- Jail Cell Creation (chest) ----------");
|
||||
player.sendMessage(ChatColor.RED + "Chest must be a double chest, chest not selected");
|
||||
player.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||
player.sendMessage(ChatColor.RED + "No chest selected.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
}
|
||||
|
||||
finalStep(jm, cp, player);
|
||||
}
|
||||
|
||||
private void finalStep(JailManager jm, CreationPlayer cp, Player player) {
|
||||
Jail j = jm.getJail(cp.getJailName());
|
||||
Cell c = new Cell(cp.getCellName());
|
||||
|
||||
c.addAllSigns(cp.getSigns());
|
||||
c.setTeleport(cp.getTeleportInSL());
|
||||
|
||||
if(cp.getChestLocation() != null)
|
||||
c.setChestLocation(cp.getChestLocation());
|
||||
|
||||
j.addCell(c, true);
|
||||
|
||||
jm.removeCellCreationPlayer(player.getName());
|
||||
jm.addCreatingCell(player.getName(), j.getName(), "cell_n" + (j.getCellCount() + 1));
|
||||
|
||||
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||
player.sendMessage(ChatColor.GREEN + "Cell created. Now select the teleport point of the next cell, which is going to be named '" + jm.getCellCreationPlayer(player.getName()).getCellName() + "'. If you wish to stop creating cells, type /jail stop.");
|
||||
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
}
|
||||
}
|
||||
|
@ -1,146 +1,146 @@
|
||||
package com.graywolf336.jail.steps;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.CreationPlayer;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
|
||||
/**
|
||||
* Class for stepping a player through the Jail creation process, instance is stored in {@link JailManager}.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.1.1
|
||||
*/
|
||||
public class JailCreationSteps {
|
||||
|
||||
/** Sends the Jail Creation message for starting out. */
|
||||
public void startStepping(Player player) {
|
||||
player.sendMessage(ChatColor.AQUA + "----------Jail Zone Creation----------");
|
||||
player.sendMessage(ChatColor.GREEN + "First, you must select jail cuboid. Select the first point of the cuboid by right clicking on the block with your wooden sword. DO NOT FORGET TO MARK THE FLOOR AND CEILING TOO!");
|
||||
player.sendMessage(ChatColor.AQUA + "--------------------------------------");
|
||||
|
||||
ItemStack wand = Util.getWand();
|
||||
if(player.getInventory().contains(wand)) {
|
||||
int i = player.getInventory().first(wand);
|
||||
if(i != -1) {
|
||||
player.getInventory().setItem(i, player.getItemInHand());
|
||||
player.setItemInHand(wand);
|
||||
}
|
||||
}else {
|
||||
player.getInventory().addItem(wand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the next step in the Jail Creation process that involves a location, null if no location is needed.
|
||||
*
|
||||
* @param jm The {@link JailManager} instance.
|
||||
* @param player The player who is doing the creating.
|
||||
* @param cp The {@link CreationPlayer} instance
|
||||
* @param location The location, null if none, being set.
|
||||
*/
|
||||
public void step(JailManager jm, Player player, CreationPlayer cp, Location location) {
|
||||
jm.getPlugin().debug("Stepping into step #" + cp.getStep());
|
||||
switch(cp.getStep()) {
|
||||
case 1:
|
||||
firstStep(cp, player, location);
|
||||
break;
|
||||
case 2:
|
||||
secondStep(cp, player, location);
|
||||
break;
|
||||
case 3:
|
||||
thirdStep(cp, player);
|
||||
break;
|
||||
case 4:
|
||||
fourthStep(jm, cp, player);
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over");
|
||||
jm.removeJailCreationPlayer(player.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the first step, which is setting the first corner. */
|
||||
private void firstStep(CreationPlayer cp, Player p, Location location) {
|
||||
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation----------");
|
||||
p.sendMessage(ChatColor.GREEN + "First point selected. Now select the second point.");
|
||||
p.sendMessage(ChatColor.AQUA + "---------------------------------------");
|
||||
|
||||
cp.setCornerOne(location);
|
||||
cp.nextStep();
|
||||
}
|
||||
|
||||
/** Applies the second step, which is setting the second corner. */
|
||||
private void secondStep(CreationPlayer cp, Player p, Location location) {
|
||||
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.GREEN + "Second point selected. Now go inside the jail and right click anywhere to select your current position as the teleport location for the jail.");
|
||||
p.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
cp.setCornerTwo(location);
|
||||
cp.nextStep();
|
||||
}
|
||||
|
||||
/** Applies the third step, which is setting the teleport in location. */
|
||||
private void thirdStep(CreationPlayer cp, Player p) {
|
||||
|
||||
int[] p1 = cp.getCornerOne();
|
||||
int[] p2 = cp.getCornerTwo();
|
||||
Vector v1 = new Vector(p1[0], p1[1], p1[2]);
|
||||
Vector v2 = new Vector(p2[0], p2[1], p2[2]);
|
||||
Vector point = p.getLocation().toVector().clone();
|
||||
|
||||
if(Util.isInsideAB(point, v1, v2)) {
|
||||
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.GREEN + "Teleport point selected. Now go outside of the jail and right click anywhere to select your current position as the location where people will be teleported after they are released from this jail.");
|
||||
p.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
cp.setTeleportIn(p.getLocation());
|
||||
cp.nextStep();
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.RED + "Teleport point NOT selected. Now go inside the jail and right click anywhere to select your current position as the teleport location for the jail. Point must be INSIDE the points selected for the Jail.");
|
||||
p.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
private void fourthStep(JailManager jm, CreationPlayer cp, Player p) {
|
||||
int[] p1 = cp.getCornerOne();
|
||||
int[] p2 = cp.getCornerTwo();
|
||||
Vector v1 = new Vector(p1[0], p1[1], p1[2]);
|
||||
Vector v2 = new Vector(p2[0], p2[1], p2[2]);
|
||||
Vector point = p.getLocation().toVector().clone();
|
||||
|
||||
if(Util.isInsideAB(point, v1, v2)) {
|
||||
p.sendMessage(ChatColor.RED + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.RED + "Teleport out point NOT selected. Go outside of the jail and right click anywhere to select your current position as the location where people will be teleported after they are released from this jail.");
|
||||
p.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
}else {
|
||||
cp.setTeleportFree(p.getLocation());
|
||||
|
||||
finalStep(jm, cp, p);
|
||||
}
|
||||
}
|
||||
|
||||
private void finalStep(JailManager jm, CreationPlayer cp, Player p) {
|
||||
Jail jail = new Jail(jm.getPlugin(), cp.getJailName());
|
||||
|
||||
jail.setMinPoint(cp.getCornerOne());
|
||||
jail.setMaxPoint(cp.getCornerTwo());
|
||||
jail.setTeleportIn(cp.getTeleportInSL().getLocation());
|
||||
jail.setTeleportFree(cp.getTeleportFreeSL().getLocation());
|
||||
|
||||
jm.addJail(jail, true);
|
||||
|
||||
p.sendMessage(ChatColor.GREEN + "Jail (" + jail.getName() + ") created successfully!");
|
||||
|
||||
jm.removeJailCreationPlayer(p.getName());
|
||||
}
|
||||
}
|
||||
package com.graywolf336.jail.steps;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.graywolf336.jail.JailManager;
|
||||
import com.graywolf336.jail.Util;
|
||||
import com.graywolf336.jail.beans.CreationPlayer;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
|
||||
/**
|
||||
* Class for stepping a player through the Jail creation process, instance is stored in {@link JailManager}.
|
||||
*
|
||||
* @author graywolf336
|
||||
* @since 3.0.0
|
||||
* @version 1.1.1
|
||||
*/
|
||||
public class JailCreationSteps {
|
||||
|
||||
/** Sends the Jail Creation message for starting out. */
|
||||
public void startStepping(Player player) {
|
||||
player.sendMessage(ChatColor.AQUA + "----------Jail Zone Creation----------");
|
||||
player.sendMessage(ChatColor.GREEN + "First, you must select jail cuboid. Select the first point of the cuboid by right clicking on the block with your wooden sword. DO NOT FORGET TO MARK THE FLOOR AND CEILING TOO!");
|
||||
player.sendMessage(ChatColor.AQUA + "--------------------------------------");
|
||||
|
||||
ItemStack wand = Util.getWand();
|
||||
if(player.getInventory().contains(wand)) {
|
||||
int i = player.getInventory().first(wand);
|
||||
if(i != -1) {
|
||||
player.getInventory().setItem(i, player.getItemInHand());
|
||||
player.setItemInHand(wand);
|
||||
}
|
||||
}else {
|
||||
player.getInventory().addItem(wand);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the next step in the Jail Creation process that involves a location, null if no location is needed.
|
||||
*
|
||||
* @param jm The {@link JailManager} instance.
|
||||
* @param player The player who is doing the creating.
|
||||
* @param cp The {@link CreationPlayer} instance
|
||||
* @param location The location, null if none, being set.
|
||||
*/
|
||||
public void step(JailManager jm, Player player, CreationPlayer cp, Location location) {
|
||||
jm.getPlugin().debug("Stepping into step #" + cp.getStep());
|
||||
switch(cp.getStep()) {
|
||||
case 1:
|
||||
firstStep(cp, player, location);
|
||||
break;
|
||||
case 2:
|
||||
secondStep(cp, player, location);
|
||||
break;
|
||||
case 3:
|
||||
thirdStep(cp, player);
|
||||
break;
|
||||
case 4:
|
||||
fourthStep(jm, cp, player);
|
||||
break;
|
||||
default:
|
||||
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over");
|
||||
jm.removeJailCreationPlayer(player.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Applies the first step, which is setting the first corner. */
|
||||
private void firstStep(CreationPlayer cp, Player p, Location location) {
|
||||
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation----------");
|
||||
p.sendMessage(ChatColor.GREEN + "First point selected. Now select the second point.");
|
||||
p.sendMessage(ChatColor.AQUA + "---------------------------------------");
|
||||
|
||||
cp.setCornerOne(location);
|
||||
cp.nextStep();
|
||||
}
|
||||
|
||||
/** Applies the second step, which is setting the second corner. */
|
||||
private void secondStep(CreationPlayer cp, Player p, Location location) {
|
||||
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.GREEN + "Second point selected. Now go inside the jail and right click anywhere to select your current position as the teleport location for the jail.");
|
||||
p.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
cp.setCornerTwo(location);
|
||||
cp.nextStep();
|
||||
}
|
||||
|
||||
/** Applies the third step, which is setting the teleport in location. */
|
||||
private void thirdStep(CreationPlayer cp, Player p) {
|
||||
|
||||
int[] p1 = cp.getCornerOne();
|
||||
int[] p2 = cp.getCornerTwo();
|
||||
Vector v1 = new Vector(p1[0], p1[1], p1[2]);
|
||||
Vector v2 = new Vector(p2[0], p2[1], p2[2]);
|
||||
Vector point = p.getLocation().toVector().clone();
|
||||
|
||||
if(Util.isInsideAB(point, v1, v2)) {
|
||||
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.GREEN + "Teleport point selected. Now go outside of the jail and right click anywhere to select your current position as the location where people will be teleported after they are released from this jail.");
|
||||
p.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||
|
||||
cp.setTeleportIn(p.getLocation());
|
||||
cp.nextStep();
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.RED + "Teleport point NOT selected. Now go inside the jail and right click anywhere to select your current position as the teleport location for the jail. Point must be INSIDE the points selected for the Jail.");
|
||||
p.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
private void fourthStep(JailManager jm, CreationPlayer cp, Player p) {
|
||||
int[] p1 = cp.getCornerOne();
|
||||
int[] p2 = cp.getCornerTwo();
|
||||
Vector v1 = new Vector(p1[0], p1[1], p1[2]);
|
||||
Vector v2 = new Vector(p2[0], p2[1], p2[2]);
|
||||
Vector point = p.getLocation().toVector().clone();
|
||||
|
||||
if(Util.isInsideAB(point, v1, v2)) {
|
||||
p.sendMessage(ChatColor.RED + "---------- Jail Zone Creation ----------");
|
||||
p.sendMessage(ChatColor.RED + "Teleport out point NOT selected. Go outside of the jail and right click anywhere to select your current position as the location where people will be teleported after they are released from this jail.");
|
||||
p.sendMessage(ChatColor.RED + "----------------------------------------");
|
||||
}else {
|
||||
cp.setTeleportFree(p.getLocation());
|
||||
|
||||
finalStep(jm, cp, p);
|
||||
}
|
||||
}
|
||||
|
||||
private void finalStep(JailManager jm, CreationPlayer cp, Player p) {
|
||||
Jail jail = new Jail(jm.getPlugin(), cp.getJailName());
|
||||
|
||||
jail.setMinPoint(cp.getCornerOne());
|
||||
jail.setMaxPoint(cp.getCornerTwo());
|
||||
jail.setTeleportIn(cp.getTeleportInSL().getLocation());
|
||||
jail.setTeleportFree(cp.getTeleportFreeSL().getLocation());
|
||||
|
||||
jm.addJail(jail, true);
|
||||
|
||||
p.sendMessage(ChatColor.GREEN + "Jail (" + jail.getName() + ") created successfully!");
|
||||
|
||||
jm.removeJailCreationPlayer(p.getName());
|
||||
}
|
||||
}
|
||||
|
@ -1,73 +1,73 @@
|
||||
system:
|
||||
configVersion: 3
|
||||
debug: false
|
||||
language: 'en'
|
||||
updateNotifications: true
|
||||
useBukkitTimer: true
|
||||
storage:
|
||||
type: 'flatfile' #can be flatfile, sqlite, or mysql
|
||||
mysql:
|
||||
host: 'localhost'
|
||||
port: 3306
|
||||
username: 'root'
|
||||
password: 'password'
|
||||
database: 'jailDatabase'
|
||||
prefix: 'j3_'
|
||||
jailing:
|
||||
during:
|
||||
blockBreakPenalty: 5m
|
||||
blockBreakProtection: true
|
||||
blockBreakWhiteList: ['crops', 'carrot', 'potato'] # these blocks can be broken at any time by prisoners
|
||||
blockPlacePenalty: 5m
|
||||
blockPlaceProtection: true
|
||||
blockPlaceWhiteList: ['crops', 'carrot', 'potato'] # these blocks can be placed at any time by prisoners
|
||||
commandPenalty: 5m
|
||||
commandProtection: true
|
||||
commandWhitelist: ['/ping', '/list', '/jail status', '/jail pay']
|
||||
countDownTimeWhileOffline: false
|
||||
cropTramplingPenalty: 5m
|
||||
cropTramplingProtection: true
|
||||
foodControl: true
|
||||
foodControlMax: 20
|
||||
foodControlMin: 10
|
||||
ignoreSleeping: true
|
||||
maxAFKTime: 10m #in minutes
|
||||
movePenalty: 10m
|
||||
moveProtection: true
|
||||
openChest: true
|
||||
preventInteractionBlocks: ['wooden_door', 'iron_door_block']
|
||||
preventInteractionBlocksPenalty: 5m
|
||||
preventInteractionItems: []
|
||||
preventInteractionItemsPenalty: 5m
|
||||
recieveMessages: true
|
||||
scoreboard:
|
||||
enabled: false
|
||||
title: 'Jail Info'
|
||||
time: '&aTime:'
|
||||
jail:
|
||||
automaticMute: true
|
||||
broadcastJailing: false
|
||||
commands: []
|
||||
defaultJail: nearest #the jail nearest to the player
|
||||
defaultTime: 30m #default the time to 30 minutes, if no time
|
||||
deleteInventory: false
|
||||
gameMode: adventure
|
||||
logToConsole: true
|
||||
logToProfile: false
|
||||
storeInventory: true
|
||||
release:
|
||||
backToPreviousPosition: false
|
||||
commands: []
|
||||
restorePreviousGameMode: false
|
||||
teleport: true
|
||||
jails:
|
||||
endermenProtection: true
|
||||
explosionProtection: true
|
||||
jailpay:
|
||||
enabled: true
|
||||
item: air
|
||||
pricePerMinute: 1.5
|
||||
priceInfinite: 10000
|
||||
jailstick:
|
||||
enabled: true
|
||||
system:
|
||||
configVersion: 3
|
||||
debug: false
|
||||
language: 'en'
|
||||
updateNotifications: true
|
||||
useBukkitTimer: true
|
||||
storage:
|
||||
type: 'flatfile' #can be flatfile, sqlite, or mysql
|
||||
mysql:
|
||||
host: 'localhost'
|
||||
port: 3306
|
||||
username: 'root'
|
||||
password: 'password'
|
||||
database: 'jailDatabase'
|
||||
prefix: 'j3_'
|
||||
jailing:
|
||||
during:
|
||||
blockBreakPenalty: 5m
|
||||
blockBreakProtection: true
|
||||
blockBreakWhiteList: ['crops', 'carrot', 'potato'] # these blocks can be broken at any time by prisoners
|
||||
blockPlacePenalty: 5m
|
||||
blockPlaceProtection: true
|
||||
blockPlaceWhiteList: ['crops', 'carrot', 'potato'] # these blocks can be placed at any time by prisoners
|
||||
commandPenalty: 5m
|
||||
commandProtection: true
|
||||
commandWhitelist: ['/ping', '/list', '/jail status', '/jail pay']
|
||||
countDownTimeWhileOffline: false
|
||||
cropTramplingPenalty: 5m
|
||||
cropTramplingProtection: true
|
||||
foodControl: true
|
||||
foodControlMax: 20
|
||||
foodControlMin: 10
|
||||
ignoreSleeping: true
|
||||
maxAFKTime: 10m #in minutes
|
||||
movePenalty: 10m
|
||||
moveProtection: true
|
||||
openChest: true
|
||||
preventInteractionBlocks: ['wooden_door', 'iron_door_block']
|
||||
preventInteractionBlocksPenalty: 5m
|
||||
preventInteractionItems: []
|
||||
preventInteractionItemsPenalty: 5m
|
||||
recieveMessages: true
|
||||
scoreboard:
|
||||
enabled: false
|
||||
title: 'Jail Info'
|
||||
time: '&aTime:'
|
||||
jail:
|
||||
automaticMute: true
|
||||
broadcastJailing: false
|
||||
commands: []
|
||||
defaultJail: nearest #the jail nearest to the player
|
||||
defaultTime: 30m #default the time to 30 minutes, if no time
|
||||
deleteInventory: false
|
||||
gameMode: adventure
|
||||
logToConsole: true
|
||||
logToProfile: false
|
||||
storeInventory: true
|
||||
release:
|
||||
backToPreviousPosition: false
|
||||
commands: []
|
||||
restorePreviousGameMode: false
|
||||
teleport: true
|
||||
jails:
|
||||
endermenProtection: true
|
||||
explosionProtection: true
|
||||
jailpay:
|
||||
enabled: true
|
||||
item: air
|
||||
pricePerMinute: 1.5
|
||||
priceInfinite: 10000
|
||||
jailstick:
|
||||
enabled: true
|
||||
sticks: ["stick,30,,Running away"]
|
@ -1,97 +1,97 @@
|
||||
language:
|
||||
actions:
|
||||
blockbreaking: 'breaking a block'
|
||||
blockplacing: 'placing a block'
|
||||
command: 'trying to use a command'
|
||||
croptrampling: 'trampling crops'
|
||||
interactionblocks: 'interacting with a block'
|
||||
interactionitems: 'interacting with an item'
|
||||
moving: 'trying to escape'
|
||||
confirm:
|
||||
already: "&cYou are already confirming something else, please type '&b/jail confirm&c' to confirm it."
|
||||
expired: '&cYour confirmation expired already, retype what you are trying to confirm.'
|
||||
nothing: '&cYou are not confirming anything.'
|
||||
start: "&cPlease type '&b/jail confirm&c' to confirm we should continue."
|
||||
general:
|
||||
alljails: 'all the jails'
|
||||
cellremovalunsuccessful: '&cThe removal of cell %0% from jail %1% was unsuccessful because there is a prisoner in there still. Release or transfer before trying to remove the cell again.'
|
||||
cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
|
||||
jailing: '&9jailing'
|
||||
jailremovalunsuccessful: '&cThe removal of the jail %0% was unsuccessful because there are prisoners in there, please release or transfer them first.'
|
||||
jailremoved: '&9Jail %0% has been successfully deleted.'
|
||||
jailstickdisabled: '&3Jail stick usage: &cdisabled'
|
||||
jailstickenabled: '&3Jail stick usage: &aenabled'
|
||||
jailstickusagedisabled: '&cThe usage of Jail Sticks has been disabled by the Administrator.'
|
||||
nocell: '&cNo cell found by the name of %0% in the jail %1%.'
|
||||
nocells: '&cNo cells found in the jail %0%.'
|
||||
nojail: '&cNo jail found by the name of %0%.'
|
||||
nojails: '&cThere are currently no jails.'
|
||||
nopermission: '&cInsufficient permission.'
|
||||
numberformatincorrect: '&cNumber format is incorrect.'
|
||||
playercontextrequired: '&cA player context is required for this.'
|
||||
playernotonline: '&cThat player is not online!'
|
||||
pluginreloaded: '&9Jail data successfully reloaded.'
|
||||
prisonerscleared: '&cAll the prisoners from %0% have been cleared.'
|
||||
recordentry: '&7[%0%]: &9%1% &fjailed by &9%2% &ffor &9%3% &fminutes with a reason of &9%4%&f. [%5%]'
|
||||
recordtimesjailed: '&c%0% has been jailed &a%1% &ctimes.'
|
||||
timeformat: "MM/dd/yyyy HH:mm:ss"
|
||||
transferring: '&9transferring'
|
||||
unknowncommand: '&cNo commands registered by the name of %0%.'
|
||||
jailing:
|
||||
afkkickmessage: '&cYou can not be afk while being jailed.'
|
||||
alreadyjailed: '&c%0% is already jailed.'
|
||||
broadcastmessageforever: '&9%0% has been jailed forever.'
|
||||
broadcastmessageforminutes: '&9%0% has been jailed for %1% minutes.'
|
||||
broadcastunjailing: '&9%0% has been unjailed by %1%.'
|
||||
cancelledbyanotherplugin: '&cJailing %0% was cancelled by another plugin and they did not leave you a message.'
|
||||
cantbejailed: '&cThat player can not be jailed.'
|
||||
cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.'
|
||||
defaultjailedreason: 'Breaking the rules.'
|
||||
forceunjailed: '&c%0% was forcefully unjailed.'
|
||||
jailed: '&cYou have been jailed!'
|
||||
jailedwithreason: '&cYou have been jailed for: %0%'
|
||||
muted: '&cStop talking, you are in jail.'
|
||||
noemptycells: '&cNo empty cells were found for %0%, all them appear to be full.'
|
||||
noprisoners: '&9%0% is empty and contains no prisoners.'
|
||||
notjailed: '&c%0% is not jailed.'
|
||||
nowmuted: '&9%0% is now muted.'
|
||||
nowunmuted: '&9%0% is now unmuted.'
|
||||
offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.'
|
||||
onlinejail: '&2%0% was jailed for %1% minutes.'
|
||||
prisonerstime: '&2%0% has %1% minutes remaining.'
|
||||
protectionmessage: '&c%0% minutes have been added to your time for %1%.'
|
||||
protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
|
||||
provideaplayer: '&cPlease provide a player when %0% &cthem.'
|
||||
provideajail: '&cPlease provide a jail to %0% &cthem to.'
|
||||
status: "&2You have been jailed with a reason of '%0%' by %1% and have %2% minutes remaining."
|
||||
suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
|
||||
telein: "&9Teleported %0% to %1%'s teleport in location."
|
||||
teleout: "&9Teleported %0% to %1%'s teleport out location."
|
||||
transferallcomplete: '&2Successfully transferred all the prisoners from %0% to %1%.'
|
||||
transfercancelledbyanotherplugin: '&cTransferring %0% was cancelled by another plugin and they did not leave you a message.'
|
||||
transfercompletecell: '&2Successfully transferred %0% to %1% in the cell %2%.'
|
||||
transfercompletenocell: '&2Successfully transferred %0% to %1%.'
|
||||
transferred: '&9You have been transferred to %0%.'
|
||||
unjailed: '&2You have been released! Please respect the server rules.'
|
||||
willbeunjailed: '&2%0% will be released the next time they log on.'
|
||||
youarenotjailed: '&2You are not jailed.'
|
||||
jailpay:
|
||||
cantpayforotherswhilejailed: '&cYou are jailed and as a result you can not pay for others.'
|
||||
cost: '&9You have to pay %0% %1% per minute which equates to %2% %1%.'
|
||||
costinfinite: '&9Since you are jailed forever, you have to pay %0% %1%.'
|
||||
nonegativeamounts: '&cYou can not pay negative amounts.'
|
||||
notenabled: "&cSorry, money won't help this time."
|
||||
notenoughmoney: "&cYou don't have that much money!"
|
||||
notenoughmoneyprovided: "&cYou have not provided enough money to cover the sentence!"
|
||||
paidreleased: "&2You have just payed %0% and released yourself from jail!"
|
||||
paidreleasedelse: "&2You have just payed %0% and released %1% from jail!"
|
||||
paidloweredtime: "&2You have just payed %0% and lowered your sentence to %1% minutes!"
|
||||
paidloweredtimeelse: "&2You have just payed %0% and lowered %1%'s sentence to %2% minutes!"
|
||||
handcuffing:
|
||||
cantbehandcuffed: '&9%0% &ccan not be handcuffed.'
|
||||
currentlyjailed: '&9%0% &cis currently jailed, you can not handcuff a prisoner.'
|
||||
nothandcuffed: '&9%0% &cdoes not have any handcuffs to remove!'
|
||||
handcuffson: '&9%0% &ahas been handcuffed!'
|
||||
handcuffed: '&cYou have been handcuffed.'
|
||||
handcuffsreleased: '&9%0% &ahas been released from their handcuffs.'
|
||||
language:
|
||||
actions:
|
||||
blockbreaking: 'breaking a block'
|
||||
blockplacing: 'placing a block'
|
||||
command: 'trying to use a command'
|
||||
croptrampling: 'trampling crops'
|
||||
interactionblocks: 'interacting with a block'
|
||||
interactionitems: 'interacting with an item'
|
||||
moving: 'trying to escape'
|
||||
confirm:
|
||||
already: "&cYou are already confirming something else, please type '&b/jail confirm&c' to confirm it."
|
||||
expired: '&cYour confirmation expired already, retype what you are trying to confirm.'
|
||||
nothing: '&cYou are not confirming anything.'
|
||||
start: "&cPlease type '&b/jail confirm&c' to confirm we should continue."
|
||||
general:
|
||||
alljails: 'all the jails'
|
||||
cellremovalunsuccessful: '&cThe removal of cell %0% from jail %1% was unsuccessful because there is a prisoner in there still. Release or transfer before trying to remove the cell again.'
|
||||
cellremoved: '&9Cell %0% has been successfully removed from the jail %1%.'
|
||||
jailing: '&9jailing'
|
||||
jailremovalunsuccessful: '&cThe removal of the jail %0% was unsuccessful because there are prisoners in there, please release or transfer them first.'
|
||||
jailremoved: '&9Jail %0% has been successfully deleted.'
|
||||
jailstickdisabled: '&3Jail stick usage: &cdisabled'
|
||||
jailstickenabled: '&3Jail stick usage: &aenabled'
|
||||
jailstickusagedisabled: '&cThe usage of Jail Sticks has been disabled by the Administrator.'
|
||||
nocell: '&cNo cell found by the name of %0% in the jail %1%.'
|
||||
nocells: '&cNo cells found in the jail %0%.'
|
||||
nojail: '&cNo jail found by the name of %0%.'
|
||||
nojails: '&cThere are currently no jails.'
|
||||
nopermission: '&cInsufficient permission.'
|
||||
numberformatincorrect: '&cNumber format is incorrect.'
|
||||
playercontextrequired: '&cA player context is required for this.'
|
||||
playernotonline: '&cThat player is not online!'
|
||||
pluginreloaded: '&9Jail data successfully reloaded.'
|
||||
prisonerscleared: '&cAll the prisoners from %0% have been cleared.'
|
||||
recordentry: '&7[%0%]: &9%1% &fjailed by &9%2% &ffor &9%3% &fminutes with a reason of &9%4%&f. [%5%]'
|
||||
recordtimesjailed: '&c%0% has been jailed &a%1% &ctimes.'
|
||||
timeformat: "MM/dd/yyyy HH:mm:ss"
|
||||
transferring: '&9transferring'
|
||||
unknowncommand: '&cNo commands registered by the name of %0%.'
|
||||
jailing:
|
||||
afkkickmessage: '&cYou can not be afk while being jailed.'
|
||||
alreadyjailed: '&c%0% is already jailed.'
|
||||
broadcastmessageforever: '&9%0% has been jailed forever.'
|
||||
broadcastmessageforminutes: '&9%0% has been jailed for %1% minutes.'
|
||||
broadcastunjailing: '&9%0% has been unjailed by %1%.'
|
||||
cancelledbyanotherplugin: '&cJailing %0% was cancelled by another plugin and they did not leave you a message.'
|
||||
cantbejailed: '&cThat player can not be jailed.'
|
||||
cellnotempty: '&cThe destination cell, %0%, already has a prisoner in it.'
|
||||
defaultjailedreason: 'Breaking the rules.'
|
||||
forceunjailed: '&c%0% was forcefully unjailed.'
|
||||
jailed: '&cYou have been jailed!'
|
||||
jailedwithreason: '&cYou have been jailed for: %0%'
|
||||
muted: '&cStop talking, you are in jail.'
|
||||
noemptycells: '&cNo empty cells were found for %0%, all them appear to be full.'
|
||||
noprisoners: '&9%0% is empty and contains no prisoners.'
|
||||
notjailed: '&c%0% is not jailed.'
|
||||
nowmuted: '&9%0% is now muted.'
|
||||
nowunmuted: '&9%0% is now unmuted.'
|
||||
offlinejail: '&2%0% is offline and will be jailed when they next come online for %1% minutes.'
|
||||
onlinejail: '&2%0% was jailed for %1% minutes.'
|
||||
prisonerstime: '&2%0% has %1% minutes remaining.'
|
||||
protectionmessage: '&c%0% minutes have been added to your time for %1%.'
|
||||
protectionmessagenopenalty: '&cProtection enabled for %0%, do not do it again.'
|
||||
provideaplayer: '&cPlease provide a player when %0% &cthem.'
|
||||
provideajail: '&cPlease provide a jail to %0% &cthem to.'
|
||||
status: "&2You have been jailed with a reason of '%0%' by %1% and have %2% minutes remaining."
|
||||
suggestedcell: '&cAn empty cell in the same jail, %0%, was found: %1%'
|
||||
telein: "&9Teleported %0% to %1%'s teleport in location."
|
||||
teleout: "&9Teleported %0% to %1%'s teleport out location."
|
||||
transferallcomplete: '&2Successfully transferred all the prisoners from %0% to %1%.'
|
||||
transfercancelledbyanotherplugin: '&cTransferring %0% was cancelled by another plugin and they did not leave you a message.'
|
||||
transfercompletecell: '&2Successfully transferred %0% to %1% in the cell %2%.'
|
||||
transfercompletenocell: '&2Successfully transferred %0% to %1%.'
|
||||
transferred: '&9You have been transferred to %0%.'
|
||||
unjailed: '&2You have been released! Please respect the server rules.'
|
||||
willbeunjailed: '&2%0% will be released the next time they log on.'
|
||||
youarenotjailed: '&2You are not jailed.'
|
||||
jailpay:
|
||||
cantpayforotherswhilejailed: '&cYou are jailed and as a result you can not pay for others.'
|
||||
cost: '&9You have to pay %0% %1% per minute which equates to %2% %1%.'
|
||||
costinfinite: '&9Since you are jailed forever, you have to pay %0% %1%.'
|
||||
nonegativeamounts: '&cYou can not pay negative amounts.'
|
||||
notenabled: "&cSorry, money won't help this time."
|
||||
notenoughmoney: "&cYou don't have that much money!"
|
||||
notenoughmoneyprovided: "&cYou have not provided enough money to cover the sentence!"
|
||||
paidreleased: "&2You have just payed %0% and released yourself from jail!"
|
||||
paidreleasedelse: "&2You have just payed %0% and released %1% from jail!"
|
||||
paidloweredtime: "&2You have just payed %0% and lowered your sentence to %1% minutes!"
|
||||
paidloweredtimeelse: "&2You have just payed %0% and lowered %1%'s sentence to %2% minutes!"
|
||||
handcuffing:
|
||||
cantbehandcuffed: '&9%0% &ccan not be handcuffed.'
|
||||
currentlyjailed: '&9%0% &cis currently jailed, you can not handcuff a prisoner.'
|
||||
nothandcuffed: '&9%0% &cdoes not have any handcuffs to remove!'
|
||||
handcuffson: '&9%0% &ahas been handcuffed!'
|
||||
handcuffed: '&cYou have been handcuffed.'
|
||||
handcuffsreleased: '&9%0% &ahas been released from their handcuffs.'
|
||||
unhandcuffed: '&aYour handcuffs have been removed.'
|
@ -1,199 +1,199 @@
|
||||
name: Jail
|
||||
main: com.graywolf336.jail.JailMain
|
||||
version: ${project.version}-b${BUILD_NUMBER}
|
||||
description: Ban too harsh? Kick/mute/whatever not enough? Jail bad players!
|
||||
authors: [matejdro,multidude,graywolf336]
|
||||
website: dev.bukkit.org/server-mods/jail/
|
||||
softdepend: [WorldEdit, Vault]
|
||||
load: POSTWORLD
|
||||
commands:
|
||||
jailcreate:
|
||||
description: Creates a new jail zone.
|
||||
jailcreatecells:
|
||||
description: Creates cells in existing jail zone.
|
||||
jailremove:
|
||||
description: Remove existing jail zone
|
||||
jail:
|
||||
description: Jail specified player for specified amount of time.
|
||||
usage: /jail [p:name] (t:time) (j:Jail name) (c:Cell name) (m:Muted) (r:Reason)
|
||||
unjail:
|
||||
description: Release a player from jail.
|
||||
unjailforce:
|
||||
description: Remove player from the database.
|
||||
jailclear:
|
||||
description: Unjail every player on the server. Use with caution!
|
||||
jailclearforce:
|
||||
description: Remove every player from the jail database.
|
||||
jailtransfer:
|
||||
description: Transfer player from current jail to another
|
||||
jailtransferall:
|
||||
description: Transfer all players in one jail to another jail
|
||||
jailcheck:
|
||||
description: Check the status of the specified player
|
||||
jailtelein:
|
||||
description: Teleport inside jail
|
||||
jailteleout:
|
||||
description: Teleport outside of the jail.
|
||||
jaillist:
|
||||
description: List all created jails
|
||||
jailstatus:
|
||||
description: Check your current jail status
|
||||
jailmute:
|
||||
description: Toggle mute of the specified prisoner
|
||||
jailstop:
|
||||
description: Stop any creation process.
|
||||
jailset:
|
||||
description: modify existing jail or prisoner.
|
||||
usage: /jailset [player/jail/cell name] [property name] (property value)
|
||||
jailpay:
|
||||
description: Pay money to be released early.
|
||||
usage: /jailpay (amount) (prisoner name)
|
||||
jailremovecells:
|
||||
description: Remove all cells from specified jail.
|
||||
jaillistcells:
|
||||
description: List all named cells from specified jail.
|
||||
jailstick:
|
||||
description: Toggle jailstick feature.
|
||||
jailcreatewe:
|
||||
description: Create a new jail zone based on existing world guard region.
|
||||
jailremovecell:
|
||||
description: Remove one cell.
|
||||
jailreload:
|
||||
description: Reload jail data
|
||||
jailrecord:
|
||||
description: Shows a players record
|
||||
jailversion:
|
||||
description: Shows the plugin version
|
||||
votejail:
|
||||
description: Allows players to vote to jail a player
|
||||
handcuff:
|
||||
description: Allows the player to handcuff another player
|
||||
unhandcuff:
|
||||
description: Allows the player to unhandcuff someone
|
||||
togglejaildebug:
|
||||
description: Toggles whether the plugin is in debugging state or not.
|
||||
permissions:
|
||||
jail.*:
|
||||
children:
|
||||
jail.command.*: true
|
||||
jail.usercmd.*: true
|
||||
jail.modifyjail: true
|
||||
jail.usejailstick280: true
|
||||
jail.canbestickjailed: true
|
||||
jail.openchest: true
|
||||
jail.canswear: true
|
||||
jail.cantbejailed: true
|
||||
jail.command.*:
|
||||
description: access to all admin commands
|
||||
children:
|
||||
jail.command.jailcreate: true
|
||||
jail.command.jailcreatecells: true
|
||||
jail.command.jailremove: true
|
||||
jail.command.jailremovecells: true
|
||||
jail.command.jail: true
|
||||
jail.command.unjail: true
|
||||
jail.command.jailtransfer: true
|
||||
jail.command.jailtransferall: true
|
||||
jail.command.jailcheck: true
|
||||
jail.command.jailtelein: true
|
||||
jail.command.jailteleout: true
|
||||
jail.command.jaillist: true
|
||||
jail.command.jaillistcells: true
|
||||
jail.command.unjailforce: true
|
||||
jail.command.jailclear: true
|
||||
jail.command.jailclearforce: true
|
||||
jail.command.jailmute: true
|
||||
jail.command.jailstop: true
|
||||
jail.command.jailset: true
|
||||
jail.command.jailcreatewe: true
|
||||
jail.command.jailremovecell: true
|
||||
jail.command.jailreload: true
|
||||
jail.command.jailrecord: true
|
||||
jail.command.handcuff: true
|
||||
jail.command.toggledebug: true
|
||||
jail.usercmd.*:
|
||||
description: access to all user commands
|
||||
children:
|
||||
jail.usercmd.jailstatus: true
|
||||
jail.usercmd.jailpay: true
|
||||
jail.usercmd.jailstick: true
|
||||
jail.usercmd.votejail: true
|
||||
jail.usercmd.votejail.player: true
|
||||
jail.usercmd.jailversion: true
|
||||
jail.command.jail:
|
||||
default: op
|
||||
jail.command.jailcreate:
|
||||
default: op
|
||||
jail.command.jailcreatecells:
|
||||
default: op
|
||||
jail.command.jailremove:
|
||||
default: op
|
||||
jail.command.jailremovecells:
|
||||
default: op
|
||||
jail.command.unjail:
|
||||
default: op
|
||||
jail.command.jailtransfer:
|
||||
default: op
|
||||
jail.command.jailtransferall:
|
||||
default: op
|
||||
jail.command.jailcheck:
|
||||
default: op
|
||||
jail.command.jailtelein:
|
||||
default: op
|
||||
jail.command.jailteleout:
|
||||
default: op
|
||||
jail.command.jaillist:
|
||||
default: op
|
||||
jail.command.jaillistcells:
|
||||
default: op
|
||||
jail.command.unjailforce:
|
||||
default: op
|
||||
jail.command.jailclear:
|
||||
default: op
|
||||
jail.command.jailclearforce:
|
||||
default: op
|
||||
jail.command.jailmute:
|
||||
default: op
|
||||
jail.command.jailstop:
|
||||
default: op
|
||||
jail.command.jailset:
|
||||
default: op
|
||||
jail.command.jailcreatewe:
|
||||
default: op
|
||||
jail.command.jailremovecell:
|
||||
default: op
|
||||
jail.command.jailreload:
|
||||
default: op
|
||||
jail.command.jailrecord:
|
||||
default: op
|
||||
jail.usercmd.jailversion:
|
||||
default: true
|
||||
jail.command.handcuff:
|
||||
default: op
|
||||
jail.usercmd.jailvote:
|
||||
default: true
|
||||
jail.usercmd.jailvote.player:
|
||||
default: op
|
||||
jail.usercmd.jailvote.immune:
|
||||
default: op
|
||||
jail.usercmd.jailstatus:
|
||||
default: true
|
||||
jail.usercmd.jailpay:
|
||||
default: true
|
||||
jail.usercmd.jailstick:
|
||||
default: true
|
||||
jail.modifyjail:
|
||||
default: op
|
||||
jail.usejailstick280:
|
||||
default: op
|
||||
description: change 280 for another jailstick item
|
||||
jail.canbestickjailed:
|
||||
default: true
|
||||
jail.openchest:
|
||||
default: op
|
||||
jail.canswear:
|
||||
default: op
|
||||
jail.cantbejailed:
|
||||
default: op
|
||||
jail.command.toggledebug:
|
||||
name: Jail
|
||||
main: com.graywolf336.jail.JailMain
|
||||
version: ${project.version}-b${BUILD_NUMBER}
|
||||
description: Ban too harsh? Kick/mute/whatever not enough? Jail bad players!
|
||||
authors: [matejdro,multidude,graywolf336]
|
||||
website: dev.bukkit.org/server-mods/jail/
|
||||
softdepend: [WorldEdit, Vault]
|
||||
load: POSTWORLD
|
||||
commands:
|
||||
jailcreate:
|
||||
description: Creates a new jail zone.
|
||||
jailcreatecells:
|
||||
description: Creates cells in existing jail zone.
|
||||
jailremove:
|
||||
description: Remove existing jail zone
|
||||
jail:
|
||||
description: Jail specified player for specified amount of time.
|
||||
usage: /jail [p:name] (t:time) (j:Jail name) (c:Cell name) (m:Muted) (r:Reason)
|
||||
unjail:
|
||||
description: Release a player from jail.
|
||||
unjailforce:
|
||||
description: Remove player from the database.
|
||||
jailclear:
|
||||
description: Unjail every player on the server. Use with caution!
|
||||
jailclearforce:
|
||||
description: Remove every player from the jail database.
|
||||
jailtransfer:
|
||||
description: Transfer player from current jail to another
|
||||
jailtransferall:
|
||||
description: Transfer all players in one jail to another jail
|
||||
jailcheck:
|
||||
description: Check the status of the specified player
|
||||
jailtelein:
|
||||
description: Teleport inside jail
|
||||
jailteleout:
|
||||
description: Teleport outside of the jail.
|
||||
jaillist:
|
||||
description: List all created jails
|
||||
jailstatus:
|
||||
description: Check your current jail status
|
||||
jailmute:
|
||||
description: Toggle mute of the specified prisoner
|
||||
jailstop:
|
||||
description: Stop any creation process.
|
||||
jailset:
|
||||
description: modify existing jail or prisoner.
|
||||
usage: /jailset [player/jail/cell name] [property name] (property value)
|
||||
jailpay:
|
||||
description: Pay money to be released early.
|
||||
usage: /jailpay (amount) (prisoner name)
|
||||
jailremovecells:
|
||||
description: Remove all cells from specified jail.
|
||||
jaillistcells:
|
||||
description: List all named cells from specified jail.
|
||||
jailstick:
|
||||
description: Toggle jailstick feature.
|
||||
jailcreatewe:
|
||||
description: Create a new jail zone based on existing world guard region.
|
||||
jailremovecell:
|
||||
description: Remove one cell.
|
||||
jailreload:
|
||||
description: Reload jail data
|
||||
jailrecord:
|
||||
description: Shows a players record
|
||||
jailversion:
|
||||
description: Shows the plugin version
|
||||
votejail:
|
||||
description: Allows players to vote to jail a player
|
||||
handcuff:
|
||||
description: Allows the player to handcuff another player
|
||||
unhandcuff:
|
||||
description: Allows the player to unhandcuff someone
|
||||
togglejaildebug:
|
||||
description: Toggles whether the plugin is in debugging state or not.
|
||||
permissions:
|
||||
jail.*:
|
||||
children:
|
||||
jail.command.*: true
|
||||
jail.usercmd.*: true
|
||||
jail.modifyjail: true
|
||||
jail.usejailstick280: true
|
||||
jail.canbestickjailed: true
|
||||
jail.openchest: true
|
||||
jail.canswear: true
|
||||
jail.cantbejailed: true
|
||||
jail.command.*:
|
||||
description: access to all admin commands
|
||||
children:
|
||||
jail.command.jailcreate: true
|
||||
jail.command.jailcreatecells: true
|
||||
jail.command.jailremove: true
|
||||
jail.command.jailremovecells: true
|
||||
jail.command.jail: true
|
||||
jail.command.unjail: true
|
||||
jail.command.jailtransfer: true
|
||||
jail.command.jailtransferall: true
|
||||
jail.command.jailcheck: true
|
||||
jail.command.jailtelein: true
|
||||
jail.command.jailteleout: true
|
||||
jail.command.jaillist: true
|
||||
jail.command.jaillistcells: true
|
||||
jail.command.unjailforce: true
|
||||
jail.command.jailclear: true
|
||||
jail.command.jailclearforce: true
|
||||
jail.command.jailmute: true
|
||||
jail.command.jailstop: true
|
||||
jail.command.jailset: true
|
||||
jail.command.jailcreatewe: true
|
||||
jail.command.jailremovecell: true
|
||||
jail.command.jailreload: true
|
||||
jail.command.jailrecord: true
|
||||
jail.command.handcuff: true
|
||||
jail.command.toggledebug: true
|
||||
jail.usercmd.*:
|
||||
description: access to all user commands
|
||||
children:
|
||||
jail.usercmd.jailstatus: true
|
||||
jail.usercmd.jailpay: true
|
||||
jail.usercmd.jailstick: true
|
||||
jail.usercmd.votejail: true
|
||||
jail.usercmd.votejail.player: true
|
||||
jail.usercmd.jailversion: true
|
||||
jail.command.jail:
|
||||
default: op
|
||||
jail.command.jailcreate:
|
||||
default: op
|
||||
jail.command.jailcreatecells:
|
||||
default: op
|
||||
jail.command.jailremove:
|
||||
default: op
|
||||
jail.command.jailremovecells:
|
||||
default: op
|
||||
jail.command.unjail:
|
||||
default: op
|
||||
jail.command.jailtransfer:
|
||||
default: op
|
||||
jail.command.jailtransferall:
|
||||
default: op
|
||||
jail.command.jailcheck:
|
||||
default: op
|
||||
jail.command.jailtelein:
|
||||
default: op
|
||||
jail.command.jailteleout:
|
||||
default: op
|
||||
jail.command.jaillist:
|
||||
default: op
|
||||
jail.command.jaillistcells:
|
||||
default: op
|
||||
jail.command.unjailforce:
|
||||
default: op
|
||||
jail.command.jailclear:
|
||||
default: op
|
||||
jail.command.jailclearforce:
|
||||
default: op
|
||||
jail.command.jailmute:
|
||||
default: op
|
||||
jail.command.jailstop:
|
||||
default: op
|
||||
jail.command.jailset:
|
||||
default: op
|
||||
jail.command.jailcreatewe:
|
||||
default: op
|
||||
jail.command.jailremovecell:
|
||||
default: op
|
||||
jail.command.jailreload:
|
||||
default: op
|
||||
jail.command.jailrecord:
|
||||
default: op
|
||||
jail.usercmd.jailversion:
|
||||
default: true
|
||||
jail.command.handcuff:
|
||||
default: op
|
||||
jail.usercmd.jailvote:
|
||||
default: true
|
||||
jail.usercmd.jailvote.player:
|
||||
default: op
|
||||
jail.usercmd.jailvote.immune:
|
||||
default: op
|
||||
jail.usercmd.jailstatus:
|
||||
default: true
|
||||
jail.usercmd.jailpay:
|
||||
default: true
|
||||
jail.usercmd.jailstick:
|
||||
default: true
|
||||
jail.modifyjail:
|
||||
default: op
|
||||
jail.usejailstick280:
|
||||
default: op
|
||||
description: change 280 for another jailstick item
|
||||
jail.canbestickjailed:
|
||||
default: true
|
||||
jail.openchest:
|
||||
default: op
|
||||
jail.canswear:
|
||||
default: op
|
||||
jail.cantbejailed:
|
||||
default: op
|
||||
jail.command.toggledebug:
|
||||
default: op
|
@ -1,83 +1,83 @@
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
|
||||
public class TestJailStuff {
|
||||
private static TestInstanceCreator creator;
|
||||
private static JailMain main;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertNotNull("The instance creator is null.", creator);
|
||||
assertTrue(creator.setup());
|
||||
main = creator.getMain();
|
||||
assertNotNull("The JailMain class is null.", main);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
main = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForJails() {
|
||||
assertNotNull("The HandCuffManager is null.", main.getHandCuffManager());
|
||||
assertNotNull("The JailIO is null.", main.getJailIO());
|
||||
assertNotNull("The JailManager is null.", main.getJailManager());
|
||||
assertNotNull("The HashSet for jails return is null.", main.getJailManager().getJails());
|
||||
assertThat(main, is(main.getJailManager().getPlugin()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConfig() {
|
||||
assertEquals("The config version is not 3.", 3, main.getConfig().getInt("system.configVersion"));
|
||||
//This is enabled by default in testing.
|
||||
//assertFalse("Default debugging is on.", main.getConfig().getBoolean("system.debug"));
|
||||
assertTrue("Default updating notifications is false.", main.getConfig().getBoolean("system.updateNotifications"));
|
||||
|
||||
//Storage system
|
||||
assertEquals("The default storage system is not flatfile.", "flatfile", main.getConfig().getString("storage.type"));
|
||||
assertEquals("The default mysql host is not localhost.", "localhost", main.getConfig().getString("storage.mysql.host"));
|
||||
assertEquals("The default mysql port is not 3306.", 3306, main.getConfig().getInt("storage.mysql.port"));
|
||||
assertEquals("The default mysql username is not root.", "root", main.getConfig().getString("storage.mysql.username"));
|
||||
assertEquals("The default mysql password is not password.", "password", main.getConfig().getString("storage.mysql.password"));
|
||||
|
||||
//Settings pertaining to being jailed
|
||||
assertFalse("Default setting for counting down time while prisoner is offline is true.", main.getConfig().getBoolean("jailing.during.countDownTimeWhileOffline"));
|
||||
assertTrue("Default setting for ignoring sleeping is false.", main.getConfig().getBoolean("jailing.during.ignoreSleeping"));
|
||||
assertTrue("Default setting for opening a chest is false.", main.getConfig().getBoolean("jailing.during.openChest"));
|
||||
|
||||
//Settings pertaining to when jailed
|
||||
assertTrue("Default setting for automatically muting is false.", main.getConfig().getBoolean("jailing.jail.automaticMute"));
|
||||
assertFalse("Default setting for broadcasting a jailing is true.", main.getConfig().getBoolean("jailing.jail.broadcastJailing"));
|
||||
assertEquals("Default setting for commands contains information.", 0, main.getConfig().getList("jailing.jail.commands").size());
|
||||
assertEquals("Default setting for default jail is not 'nearest' but something else.", "nearest", main.getConfig().getString("jailing.jail.defaultJail"));
|
||||
assertEquals("Default setting for time is not 30 minutes.", "30m", main.getConfig().getString("jailing.jail.defaultTime"));
|
||||
assertFalse("Default setting for deleting inventory is true.", main.getConfig().getBoolean("jailing.jail.deleteInventory"));
|
||||
assertTrue("Default setting for logging to console when someone is jailed is false.", main.getConfig().getBoolean("jailing.jail.logToConsole"));
|
||||
assertFalse("Default setting for logging to prisoner's profile is true.", main.getConfig().getBoolean("jailing.jail.logToProfile"));
|
||||
assertTrue("Default setting for storing prisoner's inventory upon jailing is false.", main.getConfig().getBoolean("jailing.jail.storeInventory"));
|
||||
|
||||
//Settings pertaining to after a prisoner is released
|
||||
assertFalse("Default setting for releasing back to previous position is true.", main.getConfig().getBoolean("jailing.release.backToPreviousPosition"));
|
||||
assertEquals("Default setting for commands contains information.", 0, main.getConfig().getList("jailing.release.commands").size());
|
||||
assertTrue("Default setting for teleporting them out of the jail is false.", main.getConfig().getBoolean("jailing.release.teleport"));
|
||||
}
|
||||
}
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
|
||||
public class TestJailStuff {
|
||||
private static TestInstanceCreator creator;
|
||||
private static JailMain main;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
creator = new TestInstanceCreator();
|
||||
assertNotNull("The instance creator is null.", creator);
|
||||
assertTrue(creator.setup());
|
||||
main = creator.getMain();
|
||||
assertNotNull("The JailMain class is null.", main);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception {
|
||||
creator.tearDown();
|
||||
main = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForJails() {
|
||||
assertNotNull("The HandCuffManager is null.", main.getHandCuffManager());
|
||||
assertNotNull("The JailIO is null.", main.getJailIO());
|
||||
assertNotNull("The JailManager is null.", main.getJailManager());
|
||||
assertNotNull("The HashSet for jails return is null.", main.getJailManager().getJails());
|
||||
assertThat(main, is(main.getJailManager().getPlugin()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConfig() {
|
||||
assertEquals("The config version is not 3.", 3, main.getConfig().getInt("system.configVersion"));
|
||||
//This is enabled by default in testing.
|
||||
//assertFalse("Default debugging is on.", main.getConfig().getBoolean("system.debug"));
|
||||
assertTrue("Default updating notifications is false.", main.getConfig().getBoolean("system.updateNotifications"));
|
||||
|
||||
//Storage system
|
||||
assertEquals("The default storage system is not flatfile.", "flatfile", main.getConfig().getString("storage.type"));
|
||||
assertEquals("The default mysql host is not localhost.", "localhost", main.getConfig().getString("storage.mysql.host"));
|
||||
assertEquals("The default mysql port is not 3306.", 3306, main.getConfig().getInt("storage.mysql.port"));
|
||||
assertEquals("The default mysql username is not root.", "root", main.getConfig().getString("storage.mysql.username"));
|
||||
assertEquals("The default mysql password is not password.", "password", main.getConfig().getString("storage.mysql.password"));
|
||||
|
||||
//Settings pertaining to being jailed
|
||||
assertFalse("Default setting for counting down time while prisoner is offline is true.", main.getConfig().getBoolean("jailing.during.countDownTimeWhileOffline"));
|
||||
assertTrue("Default setting for ignoring sleeping is false.", main.getConfig().getBoolean("jailing.during.ignoreSleeping"));
|
||||
assertTrue("Default setting for opening a chest is false.", main.getConfig().getBoolean("jailing.during.openChest"));
|
||||
|
||||
//Settings pertaining to when jailed
|
||||
assertTrue("Default setting for automatically muting is false.", main.getConfig().getBoolean("jailing.jail.automaticMute"));
|
||||
assertFalse("Default setting for broadcasting a jailing is true.", main.getConfig().getBoolean("jailing.jail.broadcastJailing"));
|
||||
assertEquals("Default setting for commands contains information.", 0, main.getConfig().getList("jailing.jail.commands").size());
|
||||
assertEquals("Default setting for default jail is not 'nearest' but something else.", "nearest", main.getConfig().getString("jailing.jail.defaultJail"));
|
||||
assertEquals("Default setting for time is not 30 minutes.", "30m", main.getConfig().getString("jailing.jail.defaultTime"));
|
||||
assertFalse("Default setting for deleting inventory is true.", main.getConfig().getBoolean("jailing.jail.deleteInventory"));
|
||||
assertTrue("Default setting for logging to console when someone is jailed is false.", main.getConfig().getBoolean("jailing.jail.logToConsole"));
|
||||
assertFalse("Default setting for logging to prisoner's profile is true.", main.getConfig().getBoolean("jailing.jail.logToProfile"));
|
||||
assertTrue("Default setting for storing prisoner's inventory upon jailing is false.", main.getConfig().getBoolean("jailing.jail.storeInventory"));
|
||||
|
||||
//Settings pertaining to after a prisoner is released
|
||||
assertFalse("Default setting for releasing back to previous position is true.", main.getConfig().getBoolean("jailing.release.backToPreviousPosition"));
|
||||
assertEquals("Default setting for commands contains information.", 0, main.getConfig().getList("jailing.release.commands").size());
|
||||
assertTrue("Default setting for teleporting them out of the jail is false.", main.getConfig().getBoolean("jailing.release.teleport"));
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graywolf336.jail.command.commands.jewels.Jailing;
|
||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
public class TestJewelCommands {
|
||||
@Test
|
||||
public void testJailJewel() {
|
||||
String[] args = { "--player", "graywolf336", "-c", "testing", "-r", "This", "is", "a", "reason" };
|
||||
Jailing j = CliFactory.parseArguments(Jailing.class, args);
|
||||
|
||||
assertEquals("graywolf336", j.getPlayer());
|
||||
assertEquals("testing", j.getCell());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String s : j.getReason()) {
|
||||
sb.append(s).append(' ');
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
|
||||
assertEquals("This is a reason", sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferForJailAndCell() {
|
||||
String[] args = { "-p", "graywolf336", "-j", "hardcore", "-c", "cell_n01" };
|
||||
Transfer t = CliFactory.parseArguments(Transfer.class, args);
|
||||
|
||||
assertEquals("The player parsed is not what we expected.", "graywolf336", t.getPlayer());
|
||||
assertEquals("The jail parsed is not what we expected.", "hardcore", t.getJail());
|
||||
assertEquals("The cell parsed is not what we expected.", "cell_n01", t.getCell());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferForNoCell() {
|
||||
String[] args = { "-p", "graywolf336", "-j", "hardcore" };
|
||||
Transfer t = CliFactory.parseArguments(Transfer.class, args);
|
||||
|
||||
assertEquals("The player parsed is not what we expected.", "graywolf336", t.getPlayer());
|
||||
assertEquals("The jail parsed is not what we expected.", "hardcore", t.getJail());
|
||||
assertNull("The cell is not null?", t.getCell());
|
||||
}
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graywolf336.jail.command.commands.jewels.Jailing;
|
||||
import com.graywolf336.jail.command.commands.jewels.Transfer;
|
||||
import com.lexicalscope.jewel.cli.CliFactory;
|
||||
|
||||
public class TestJewelCommands {
|
||||
@Test
|
||||
public void testJailJewel() {
|
||||
String[] args = { "--player", "graywolf336", "-c", "testing", "-r", "This", "is", "a", "reason" };
|
||||
Jailing j = CliFactory.parseArguments(Jailing.class, args);
|
||||
|
||||
assertEquals("graywolf336", j.getPlayer());
|
||||
assertEquals("testing", j.getCell());
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(String s : j.getReason()) {
|
||||
sb.append(s).append(' ');
|
||||
}
|
||||
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
|
||||
assertEquals("This is a reason", sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferForJailAndCell() {
|
||||
String[] args = { "-p", "graywolf336", "-j", "hardcore", "-c", "cell_n01" };
|
||||
Transfer t = CliFactory.parseArguments(Transfer.class, args);
|
||||
|
||||
assertEquals("The player parsed is not what we expected.", "graywolf336", t.getPlayer());
|
||||
assertEquals("The jail parsed is not what we expected.", "hardcore", t.getJail());
|
||||
assertEquals("The cell parsed is not what we expected.", "cell_n01", t.getCell());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferForNoCell() {
|
||||
String[] args = { "-p", "graywolf336", "-j", "hardcore" };
|
||||
Transfer t = CliFactory.parseArguments(Transfer.class, args);
|
||||
|
||||
assertEquals("The player parsed is not what we expected.", "graywolf336", t.getPlayer());
|
||||
assertEquals("The jail parsed is not what we expected.", "hardcore", t.getJail());
|
||||
assertNull("The cell is not null?", t.getCell());
|
||||
}
|
||||
}
|
@ -1,43 +1,43 @@
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graywolf336.jail.Util;
|
||||
|
||||
public class TestTimeParsing {
|
||||
|
||||
@Test
|
||||
public void testNoFormat() throws Exception {
|
||||
assertThat(60000L, is(Util.getTime("1")));
|
||||
assertThat(360000L, is(Util.getTime("6")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeconds() throws Exception {
|
||||
assertThat(2000L, is(Util.getTime("2s")));
|
||||
assertThat(2000L, is(Util.getTime("2second")));
|
||||
assertThat(2000L, is(Util.getTime("2seconds")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutes() throws Exception {
|
||||
assertThat(60000L, is(Util.getTime("1m")));
|
||||
assertThat(60000L, is(Util.getTime("1minute")));
|
||||
assertThat(60000L, is(Util.getTime("1minutes")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHours() throws Exception {
|
||||
assertThat(3600000L, is(Util.getTime("1h")));
|
||||
assertThat(3600000L, is(Util.getTime("1hours")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDays() throws Exception {
|
||||
assertThat(86400000L, is(Util.getTime("1d")));
|
||||
assertThat(86400000L, is(Util.getTime("1days")));
|
||||
}
|
||||
}
|
||||
package test.java.com.graywolf336.jail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graywolf336.jail.Util;
|
||||
|
||||
public class TestTimeParsing {
|
||||
|
||||
@Test
|
||||
public void testNoFormat() throws Exception {
|
||||
assertThat(60000L, is(Util.getTime("1")));
|
||||
assertThat(360000L, is(Util.getTime("6")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeconds() throws Exception {
|
||||
assertThat(2000L, is(Util.getTime("2s")));
|
||||
assertThat(2000L, is(Util.getTime("2second")));
|
||||
assertThat(2000L, is(Util.getTime("2seconds")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinutes() throws Exception {
|
||||
assertThat(60000L, is(Util.getTime("1m")));
|
||||
assertThat(60000L, is(Util.getTime("1minute")));
|
||||
assertThat(60000L, is(Util.getTime("1minutes")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHours() throws Exception {
|
||||
assertThat(3600000L, is(Util.getTime("1h")));
|
||||
assertThat(3600000L, is(Util.getTime("1hours")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDays() throws Exception {
|
||||
assertThat(86400000L, is(Util.getTime("1d")));
|
||||
assertThat(86400000L, is(Util.getTime("1days")));
|
||||
}
|
||||
}
|
||||
|
@ -1,301 +1,301 @@
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class MockPlayerInventory implements PlayerInventory {
|
||||
|
||||
private int armorSize = 4, inventorySize = 36;
|
||||
ItemStack[] armorContents = new ItemStack[armorSize];
|
||||
ItemStack[] inventoryContents = new ItemStack[inventorySize];
|
||||
|
||||
@Override
|
||||
public ItemStack[] getArmorContents() {
|
||||
return armorContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHelmet() {
|
||||
return armorContents[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getChestplate() {
|
||||
return armorContents[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getLeggings() {
|
||||
return armorContents[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
return armorContents[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmorContents(ItemStack[] itemStacks) {
|
||||
this.armorContents = itemStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelmet(ItemStack itemStack) {
|
||||
this.armorContents[0] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChestplate(ItemStack itemStack) {
|
||||
this.armorContents[1] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeggings(ItemStack itemStack) {
|
||||
this.armorContents[2] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoots(ItemStack itemStack) {
|
||||
this.armorContents[3] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInHand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInHand(ItemStack itemStack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeldItemSlot() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clear(int i, int i2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HumanEntity getHolder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return inventoryContents.length + armorContents.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
if (i >= 0 && i < inventorySize) {
|
||||
return inventoryContents[i];
|
||||
} else if (i >= inventorySize
|
||||
&& i < inventorySize + armorSize) {
|
||||
return armorContents[i - inventorySize];
|
||||
} else {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemStack) {
|
||||
if (i >= 0 && i < inventorySize) {
|
||||
inventoryContents[i] = itemStack;
|
||||
} else if (i >= inventorySize
|
||||
&& i < inventorySize + armorSize) {
|
||||
armorContents[i - inventorySize] = itemStack;
|
||||
} else {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... itemStacks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... itemStacks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.inventoryContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContents(ItemStack[] itemStacks) {
|
||||
this.inventoryContents = itemStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int i, int i1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack itemStack, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(Material material) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(ItemStack itemStack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int firstEmpty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Material material) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack itemStack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int i) {
|
||||
inventoryContents[i] = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAtLeast(final ItemStack itemStack, final int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, Object> makeMap(ItemStack[] items) {
|
||||
Map<String, Object> contents = new LinkedHashMap<String, Object>(
|
||||
items.length);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null && items[i].getTypeId() != 0) {
|
||||
contents.put(Integer.valueOf(i).toString(), items[i]);
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "{\"inventoryContents\":" + makeMap(getContents())
|
||||
+ ",\"armorContents\":" + makeMap(getArmorContents()) + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeldItemSlot(int slot) {
|
||||
|
||||
}
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class MockPlayerInventory implements PlayerInventory {
|
||||
|
||||
private int armorSize = 4, inventorySize = 36;
|
||||
ItemStack[] armorContents = new ItemStack[armorSize];
|
||||
ItemStack[] inventoryContents = new ItemStack[inventorySize];
|
||||
|
||||
@Override
|
||||
public ItemStack[] getArmorContents() {
|
||||
return armorContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHelmet() {
|
||||
return armorContents[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getChestplate() {
|
||||
return armorContents[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getLeggings() {
|
||||
return armorContents[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getBoots() {
|
||||
return armorContents[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmorContents(ItemStack[] itemStacks) {
|
||||
this.armorContents = itemStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHelmet(ItemStack itemStack) {
|
||||
this.armorContents[0] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChestplate(ItemStack itemStack) {
|
||||
this.armorContents[1] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLeggings(ItemStack itemStack) {
|
||||
this.armorContents[2] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoots(ItemStack itemStack) {
|
||||
this.armorContents[3] = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemInHand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemInHand(ItemStack itemStack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeldItemSlot() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clear(int i, int i2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HumanEntity getHolder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return inventoryContents.length + armorContents.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
if (i >= 0 && i < inventorySize) {
|
||||
return inventoryContents[i];
|
||||
} else if (i >= inventorySize
|
||||
&& i < inventorySize + armorSize) {
|
||||
return armorContents[i - inventorySize];
|
||||
} else {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemStack) {
|
||||
if (i >= 0 && i < inventorySize) {
|
||||
inventoryContents[i] = itemStack;
|
||||
} else if (i >= inventorySize
|
||||
&& i < inventorySize + armorSize) {
|
||||
armorContents[i - inventorySize] = itemStack;
|
||||
} else {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> addItem(ItemStack... itemStacks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ItemStack> removeItem(ItemStack... itemStacks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.inventoryContents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContents(ItemStack[] itemStacks) {
|
||||
this.inventoryContents = itemStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(int i, int i1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Material material, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(ItemStack itemStack, int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, ? extends ItemStack> all(ItemStack itemStack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(Material material) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int first(ItemStack itemStack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int firstEmpty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Material material) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(ItemStack itemStack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(int i) {
|
||||
inventoryContents[i] = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryType getType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<ItemStack> iterator(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAtLeast(final ItemStack itemStack, final int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, Object> makeMap(ItemStack[] items) {
|
||||
Map<String, Object> contents = new LinkedHashMap<String, Object>(
|
||||
items.length);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null && items[i].getTypeId() != 0) {
|
||||
contents.put(Integer.valueOf(i).toString(), items[i]);
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "{\"inventoryContents\":" + makeMap(getContents())
|
||||
+ ",\"armorContents\":" + makeMap(getArmorContents()) + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeldItemSlot(int slot) {
|
||||
|
||||
}
|
||||
}
|
@ -1,215 +1,215 @@
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class MockWorldFactory {
|
||||
|
||||
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
|
||||
private static final Map<UUID, World> worldUIDS = new HashMap<UUID, World>();
|
||||
|
||||
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Difficulty> difficultyStates = new WeakHashMap<World, Difficulty>();
|
||||
|
||||
private MockWorldFactory() {
|
||||
}
|
||||
|
||||
private static void registerWorld(World world) {
|
||||
createdWorlds.put(world.getName(), world);
|
||||
worldUIDS.put(world.getUID(), world);
|
||||
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
|
||||
}
|
||||
|
||||
private static World basics(String world, World.Environment env, WorldType type) {
|
||||
World mockWorld = mock(World.class);
|
||||
when(mockWorld.getName()).thenReturn(world);
|
||||
when(mockWorld.getPVP()).thenAnswer(new Answer<Boolean>() {
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!pvpStates.containsKey(w))
|
||||
pvpStates.put(w, true); // default value
|
||||
return pvpStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
pvpStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setPVP(anyBoolean());
|
||||
when(mockWorld.getKeepSpawnInMemory()).thenAnswer(new Answer<Boolean>() {
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!keepSpawnInMemoryStates.containsKey(w))
|
||||
keepSpawnInMemoryStates.put(w, true); // default value
|
||||
return keepSpawnInMemoryStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
keepSpawnInMemoryStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setKeepSpawnInMemory(anyBoolean());
|
||||
when(mockWorld.getDifficulty()).thenAnswer(new Answer<Difficulty>() {
|
||||
public Difficulty answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!difficultyStates.containsKey(w))
|
||||
difficultyStates.put(w, Difficulty.NORMAL); // default value
|
||||
return difficultyStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
difficultyStates.put((World) invocation.getMock(), (Difficulty) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setDifficulty(any(Difficulty.class));
|
||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||
when(mockWorld.getWorldType()).thenReturn(type);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!(invocation.getMock() instanceof World))
|
||||
return null;
|
||||
|
||||
World thiss = (World) invocation.getMock();
|
||||
return new File(TestInstanceCreator.serverDirectory, thiss.getName());
|
||||
}
|
||||
});
|
||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||
Location loc;
|
||||
try {
|
||||
loc = (Location) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
Material blockType = Material.AIR;
|
||||
Block mockBlock = mock(Block.class);
|
||||
if (loc.getBlockY() < 64) {
|
||||
blockType = Material.DIRT;
|
||||
}
|
||||
|
||||
when(mockBlock.getType()).thenReturn(blockType);
|
||||
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
|
||||
when(mockBlock.getWorld()).thenReturn(loc.getWorld());
|
||||
when(mockBlock.getX()).thenReturn(loc.getBlockX());
|
||||
when(mockBlock.getY()).thenReturn(loc.getBlockY());
|
||||
when(mockBlock.getZ()).thenReturn(loc.getBlockZ());
|
||||
when(mockBlock.getLocation()).thenReturn(loc);
|
||||
when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR);
|
||||
return mockBlock;
|
||||
}
|
||||
});
|
||||
when(mockWorld.getUID()).thenReturn(UUID.randomUUID());
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
private static World nullWorld(String world, World.Environment env, WorldType type) {
|
||||
World mockWorld = mock(World.class);
|
||||
when(mockWorld.getName()).thenReturn(world);
|
||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||
when(mockWorld.getWorldType()).thenReturn(type);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!(invocation.getMock() instanceof World))
|
||||
return null;
|
||||
|
||||
World thiss = (World) invocation.getMock();
|
||||
return new File(TestInstanceCreator.serverDirectory, thiss.getName());
|
||||
}
|
||||
});
|
||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||
Location loc;
|
||||
try {
|
||||
loc = (Location) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Block mockBlock = mock(Block.class);
|
||||
Material blockType = Material.AIR;
|
||||
|
||||
when(mockBlock.getType()).thenReturn(blockType);
|
||||
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
|
||||
when(mockBlock.getWorld()).thenReturn(loc.getWorld());
|
||||
when(mockBlock.getX()).thenReturn(loc.getBlockX());
|
||||
when(mockBlock.getY()).thenReturn(loc.getBlockY());
|
||||
when(mockBlock.getZ()).thenReturn(loc.getBlockZ());
|
||||
when(mockBlock.getLocation()).thenReturn(loc);
|
||||
when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR);
|
||||
return mockBlock;
|
||||
}
|
||||
});
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
public static World makeNewMockWorld(String world, World.Environment env, WorldType type) {
|
||||
World w = basics(world, env, type);
|
||||
registerWorld(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
public static World makeNewNullMockWorld(String world, World.Environment env, WorldType type) {
|
||||
World w = nullWorld(world, env, type);
|
||||
registerWorld(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
public static World makeNewMockWorld(String world, World.Environment env, WorldType type, long seed,
|
||||
ChunkGenerator generator) {
|
||||
World mockWorld = basics(world, env, type);
|
||||
when(mockWorld.getGenerator()).thenReturn(generator);
|
||||
when(mockWorld.getSeed()).thenReturn(seed);
|
||||
registerWorld(mockWorld);
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
public static World getWorld(String name) {
|
||||
return createdWorlds.get(name);
|
||||
}
|
||||
|
||||
public static World getWorld(UUID worldUID) {
|
||||
return worldUIDS.get(worldUID);
|
||||
}
|
||||
|
||||
public static List<World> getWorlds() {
|
||||
// we have to invert the order!
|
||||
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
|
||||
List<World> retList = new ArrayList<World>();
|
||||
for (int i = (myList.size() - 1); i >= 0; i--) {
|
||||
retList.add(myList.get(i));
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
|
||||
public static void clearWorlds() {
|
||||
for (String name : createdWorlds.keySet())
|
||||
new File(TestInstanceCreator.worldsDirectory, name).delete();
|
||||
createdWorlds.clear();
|
||||
worldUIDS.clear();
|
||||
}
|
||||
}
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class MockWorldFactory {
|
||||
|
||||
private static final Map<String, World> createdWorlds = new HashMap<String, World>();
|
||||
private static final Map<UUID, World> worldUIDS = new HashMap<UUID, World>();
|
||||
|
||||
private static final Map<World, Boolean> pvpStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Boolean> keepSpawnInMemoryStates = new WeakHashMap<World, Boolean>();
|
||||
private static final Map<World, Difficulty> difficultyStates = new WeakHashMap<World, Difficulty>();
|
||||
|
||||
private MockWorldFactory() {
|
||||
}
|
||||
|
||||
private static void registerWorld(World world) {
|
||||
createdWorlds.put(world.getName(), world);
|
||||
worldUIDS.put(world.getUID(), world);
|
||||
new File(TestInstanceCreator.worldsDirectory, world.getName()).mkdir();
|
||||
}
|
||||
|
||||
private static World basics(String world, World.Environment env, WorldType type) {
|
||||
World mockWorld = mock(World.class);
|
||||
when(mockWorld.getName()).thenReturn(world);
|
||||
when(mockWorld.getPVP()).thenAnswer(new Answer<Boolean>() {
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!pvpStates.containsKey(w))
|
||||
pvpStates.put(w, true); // default value
|
||||
return pvpStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
pvpStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setPVP(anyBoolean());
|
||||
when(mockWorld.getKeepSpawnInMemory()).thenAnswer(new Answer<Boolean>() {
|
||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!keepSpawnInMemoryStates.containsKey(w))
|
||||
keepSpawnInMemoryStates.put(w, true); // default value
|
||||
return keepSpawnInMemoryStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
keepSpawnInMemoryStates.put((World) invocation.getMock(), (Boolean) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setKeepSpawnInMemory(anyBoolean());
|
||||
when(mockWorld.getDifficulty()).thenAnswer(new Answer<Difficulty>() {
|
||||
public Difficulty answer(InvocationOnMock invocation) throws Throwable {
|
||||
World w = (World) invocation.getMock();
|
||||
if (!difficultyStates.containsKey(w))
|
||||
difficultyStates.put(w, Difficulty.NORMAL); // default value
|
||||
return difficultyStates.get(w);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
difficultyStates.put((World) invocation.getMock(), (Difficulty) invocation.getArguments()[0]);
|
||||
return null;
|
||||
}
|
||||
}).when(mockWorld).setDifficulty(any(Difficulty.class));
|
||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||
when(mockWorld.getWorldType()).thenReturn(type);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!(invocation.getMock() instanceof World))
|
||||
return null;
|
||||
|
||||
World thiss = (World) invocation.getMock();
|
||||
return new File(TestInstanceCreator.serverDirectory, thiss.getName());
|
||||
}
|
||||
});
|
||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||
Location loc;
|
||||
try {
|
||||
loc = (Location) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
Material blockType = Material.AIR;
|
||||
Block mockBlock = mock(Block.class);
|
||||
if (loc.getBlockY() < 64) {
|
||||
blockType = Material.DIRT;
|
||||
}
|
||||
|
||||
when(mockBlock.getType()).thenReturn(blockType);
|
||||
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
|
||||
when(mockBlock.getWorld()).thenReturn(loc.getWorld());
|
||||
when(mockBlock.getX()).thenReturn(loc.getBlockX());
|
||||
when(mockBlock.getY()).thenReturn(loc.getBlockY());
|
||||
when(mockBlock.getZ()).thenReturn(loc.getBlockZ());
|
||||
when(mockBlock.getLocation()).thenReturn(loc);
|
||||
when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR);
|
||||
return mockBlock;
|
||||
}
|
||||
});
|
||||
when(mockWorld.getUID()).thenReturn(UUID.randomUUID());
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
private static World nullWorld(String world, World.Environment env, WorldType type) {
|
||||
World mockWorld = mock(World.class);
|
||||
when(mockWorld.getName()).thenReturn(world);
|
||||
when(mockWorld.getEnvironment()).thenReturn(env);
|
||||
when(mockWorld.getWorldType()).thenReturn(type);
|
||||
when(mockWorld.getSpawnLocation()).thenReturn(new Location(mockWorld, 0, 64, 0));
|
||||
when(mockWorld.getWorldFolder()).thenAnswer(new Answer<File>() {
|
||||
public File answer(InvocationOnMock invocation) throws Throwable {
|
||||
if (!(invocation.getMock() instanceof World))
|
||||
return null;
|
||||
|
||||
World thiss = (World) invocation.getMock();
|
||||
return new File(TestInstanceCreator.serverDirectory, thiss.getName());
|
||||
}
|
||||
});
|
||||
when(mockWorld.getBlockAt(any(Location.class))).thenAnswer(new Answer<Block>() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public Block answer(InvocationOnMock invocation) throws Throwable {
|
||||
Location loc;
|
||||
try {
|
||||
loc = (Location) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Block mockBlock = mock(Block.class);
|
||||
Material blockType = Material.AIR;
|
||||
|
||||
when(mockBlock.getType()).thenReturn(blockType);
|
||||
when(mockBlock.getTypeId()).thenReturn(blockType.getId());
|
||||
when(mockBlock.getWorld()).thenReturn(loc.getWorld());
|
||||
when(mockBlock.getX()).thenReturn(loc.getBlockX());
|
||||
when(mockBlock.getY()).thenReturn(loc.getBlockY());
|
||||
when(mockBlock.getZ()).thenReturn(loc.getBlockZ());
|
||||
when(mockBlock.getLocation()).thenReturn(loc);
|
||||
when(mockBlock.isEmpty()).thenReturn(blockType == Material.AIR);
|
||||
return mockBlock;
|
||||
}
|
||||
});
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
public static World makeNewMockWorld(String world, World.Environment env, WorldType type) {
|
||||
World w = basics(world, env, type);
|
||||
registerWorld(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
public static World makeNewNullMockWorld(String world, World.Environment env, WorldType type) {
|
||||
World w = nullWorld(world, env, type);
|
||||
registerWorld(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
public static World makeNewMockWorld(String world, World.Environment env, WorldType type, long seed,
|
||||
ChunkGenerator generator) {
|
||||
World mockWorld = basics(world, env, type);
|
||||
when(mockWorld.getGenerator()).thenReturn(generator);
|
||||
when(mockWorld.getSeed()).thenReturn(seed);
|
||||
registerWorld(mockWorld);
|
||||
return mockWorld;
|
||||
}
|
||||
|
||||
public static World getWorld(String name) {
|
||||
return createdWorlds.get(name);
|
||||
}
|
||||
|
||||
public static World getWorld(UUID worldUID) {
|
||||
return worldUIDS.get(worldUID);
|
||||
}
|
||||
|
||||
public static List<World> getWorlds() {
|
||||
// we have to invert the order!
|
||||
ArrayList<World> myList = new ArrayList<World>(createdWorlds.values());
|
||||
List<World> retList = new ArrayList<World>();
|
||||
for (int i = (myList.size() - 1); i >= 0; i--) {
|
||||
retList.add(myList.get(i));
|
||||
}
|
||||
return retList;
|
||||
}
|
||||
|
||||
public static void clearWorlds() {
|
||||
for (String name : createdWorlds.keySet())
|
||||
new File(TestInstanceCreator.worldsDirectory, name).delete();
|
||||
createdWorlds.clear();
|
||||
worldUIDS.clear();
|
||||
}
|
||||
}
|
||||
|
@ -1,335 +1,335 @@
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLogger;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.MockGateway;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.powermock.api.support.membermodification.MemberMatcher.constructor;
|
||||
import static org.powermock.api.support.membermodification.MemberModifier.suppress;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
|
||||
@PrepareForTest({ CraftItemFactory.class })
|
||||
public class TestInstanceCreator {
|
||||
private JailMain main;
|
||||
private Server mockServer;
|
||||
private Player mockPlayer;
|
||||
private CommandSender mockSender, mockPlayerSender;
|
||||
private ConsoleCommandSender consoleSender;
|
||||
|
||||
public static final File serverDirectory = new File("bin" + File.separator + "test" + File.separator + "server");
|
||||
public static final File worldsDirectory = new File("bin" + File.separator + "test" + File.separator + "server");
|
||||
public static final File pluginDirectory = new File(serverDirectory + File.separator + "plugins" + File.separator + "JailTest");
|
||||
|
||||
public boolean setup() {
|
||||
try {
|
||||
pluginDirectory.mkdirs();
|
||||
Assert.assertTrue(pluginDirectory.exists());
|
||||
|
||||
MockGateway.MOCK_STANDARD_METHODS = false;
|
||||
|
||||
// Initialize the Mock server.
|
||||
mockServer = mock(Server.class);
|
||||
when(mockServer.getName()).thenReturn("TestBukkit");
|
||||
when(mockServer.getVersion()).thenReturn("Jail-Testing-0.0.1");
|
||||
when(mockServer.getBukkitVersion()).thenReturn("0.0.1");
|
||||
Logger.getLogger("Minecraft").setParent(Util.logger);
|
||||
when(mockServer.getLogger()).thenReturn(Util.logger);
|
||||
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
|
||||
when(mockServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
||||
|
||||
MockWorldFactory.makeNewMockWorld("world", Environment.NORMAL, WorldType.NORMAL);
|
||||
|
||||
suppress(constructor(JailMain.class));
|
||||
main = PowerMockito.spy(new JailMain());
|
||||
|
||||
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-Test", "com.graywolf336.jail.JailMain"));
|
||||
when(pdf.getPrefix()).thenReturn("Jail");
|
||||
List<String> authors = new ArrayList<String>();
|
||||
authors.add("matejdro");
|
||||
authors.add("multidude");
|
||||
authors.add("graywolf336");
|
||||
when(pdf.getAuthors()).thenReturn(authors);
|
||||
when(main.getDescription()).thenReturn(pdf);
|
||||
when(main.getDataFolder()).thenReturn(pluginDirectory);
|
||||
when(main.isEnabled()).thenReturn(true);
|
||||
when(main.getLogger()).thenReturn(Util.logger);
|
||||
when(main.getServer()).thenReturn(mockServer);
|
||||
|
||||
Field configFile = JavaPlugin.class.getDeclaredField("configFile");
|
||||
configFile.setAccessible(true);
|
||||
configFile.set(main, new File(pluginDirectory, "config.yml"));
|
||||
|
||||
Field logger = JavaPlugin.class.getDeclaredField("logger");
|
||||
logger.setAccessible(true);
|
||||
logger.set(main, new PluginLogger(main));
|
||||
|
||||
doReturn(getClass().getClassLoader().getResourceAsStream("config.yml")).when(main).getResource("config.yml");
|
||||
doReturn(getClass().getClassLoader().getResourceAsStream("en.yml")).when(main).getResource("en.yml");
|
||||
|
||||
// Add Jail to the list of loaded plugins
|
||||
JavaPlugin[] plugins = new JavaPlugin[] { main };
|
||||
|
||||
// Mock the Plugin Manager
|
||||
PluginManager mockPluginManager = PowerMockito.mock(PluginManager.class);
|
||||
when(mockPluginManager.getPlugins()).thenReturn(plugins);
|
||||
when(mockPluginManager.getPlugin("Jail")).thenReturn(main);
|
||||
when(mockPluginManager.getPermission(anyString())).thenReturn(null);
|
||||
|
||||
// Give the server some worlds
|
||||
when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() {
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
String arg;
|
||||
try {
|
||||
arg = (String) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return MockWorldFactory.getWorld(arg);
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getWorld(any(UUID.class))).thenAnswer(new Answer<World>() {
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
UUID arg;
|
||||
try {
|
||||
arg = (UUID) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return MockWorldFactory.getWorld(arg);
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
|
||||
public List<World> answer(InvocationOnMock invocation) throws Throwable {
|
||||
return MockWorldFactory.getWorlds();
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getPluginManager()).thenReturn(mockPluginManager);
|
||||
|
||||
when(mockServer.createWorld(Matchers.isA(WorldCreator.class))).thenAnswer(
|
||||
new Answer<World>() {
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
WorldCreator arg;
|
||||
try {
|
||||
arg = (WorldCreator) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
// Add special case for creating null worlds.
|
||||
// Not sure I like doing it this way, but this is a special case
|
||||
if (arg.name().equalsIgnoreCase("nullworld")) {
|
||||
return MockWorldFactory.makeNewNullMockWorld(arg.name(), arg.environment(), arg.type());
|
||||
}
|
||||
return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment(), arg.type());
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
|
||||
|
||||
// add mock scheduler
|
||||
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
|
||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
|
||||
thenAnswer(new Answer<Integer>() {
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
Runnable arg;
|
||||
try {
|
||||
arg = (Runnable) invocation.getArguments()[1];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
arg.run();
|
||||
return null;
|
||||
}});
|
||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
|
||||
thenAnswer(new Answer<Integer>() {
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
Runnable arg;
|
||||
try {
|
||||
arg = (Runnable) invocation.getArguments()[1];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
arg.run();
|
||||
return null;
|
||||
}});
|
||||
when(mockServer.getScheduler()).thenReturn(mockScheduler);
|
||||
|
||||
// Set server
|
||||
Field serverField = JavaPlugin.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(main, mockServer);
|
||||
|
||||
// Init our command sender
|
||||
final Logger consoleSenderLogger = Logger.getLogger("ConsoleCommandSender");
|
||||
consoleSenderLogger.setParent(Util.logger);
|
||||
consoleSender = mock(ConsoleCommandSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
consoleSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
||||
return null;
|
||||
}
|
||||
}).when(consoleSender).sendMessage(anyString());
|
||||
when(consoleSender.getServer()).thenReturn(mockServer);
|
||||
when(consoleSender.getName()).thenReturn("MockCommandSender");
|
||||
when(consoleSender.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(consoleSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(consoleSender.hasPermission(anyString())).thenReturn(true);
|
||||
when(consoleSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(consoleSender.addAttachment(main)).thenReturn(null);
|
||||
when(consoleSender.isOp()).thenReturn(true);
|
||||
when(mockServer.getConsoleSender()).thenReturn(consoleSender);
|
||||
|
||||
// Init our command sender
|
||||
final Logger commandSenderLogger = Logger.getLogger("CommandSender");
|
||||
commandSenderLogger.setParent(Util.logger);
|
||||
mockSender = mock(CommandSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
commandSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
||||
return null;
|
||||
}
|
||||
}).when(mockSender).sendMessage(anyString());
|
||||
when(mockSender.getServer()).thenReturn(mockServer);
|
||||
when(mockSender.getName()).thenReturn("MockCommandSender");
|
||||
when(mockSender.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(mockSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockSender.hasPermission(anyString())).thenReturn(true);
|
||||
when(mockSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockSender.addAttachment(main)).thenReturn(null);
|
||||
when(mockSender.isOp()).thenReturn(true);
|
||||
|
||||
// Init our player, who is op and who has all permissions (with name of graywolf336)
|
||||
mockPlayer = mock(Player.class);
|
||||
when(mockPlayer.getUniqueId()).thenReturn(UUID.fromString("062c14ba-4c47-4757-911b-bbf9a60dab7b"));
|
||||
when(mockPlayer.getName()).thenReturn("graywolf336");
|
||||
when(mockPlayer.getDisplayName()).thenReturn("TheGrayWolf");
|
||||
when(mockPlayer.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(mockPlayer.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayer.hasPermission(anyString())).thenReturn(true);
|
||||
when(mockPlayer.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayer.isOp()).thenReturn(true);
|
||||
when(mockPlayer.getInventory()).thenReturn(new MockPlayerInventory());
|
||||
|
||||
// Init our second command sender, but this time is an instance of a player
|
||||
mockPlayerSender = (CommandSender) mockPlayer;
|
||||
when(mockPlayerSender.getServer()).thenReturn(mockServer);
|
||||
when(mockPlayerSender.getName()).thenReturn("graywolf336");
|
||||
when(mockPlayerSender.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(mockPlayerSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayerSender.hasPermission(anyString())).thenReturn(true);
|
||||
when(mockPlayerSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayerSender.addAttachment(main)).thenReturn(null);
|
||||
when(mockPlayerSender.isOp()).thenReturn(true);
|
||||
|
||||
Bukkit.setServer(mockServer);
|
||||
|
||||
// Load Jail
|
||||
main.onLoad();
|
||||
|
||||
// Enable it and turn on debugging
|
||||
main.onEnable();
|
||||
main.setDebugging(true);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tearDown() {
|
||||
try {
|
||||
Field serverField = Bukkit.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(Class.forName("org.bukkit.Bukkit"), null);
|
||||
} catch (Exception e) {
|
||||
Util.log(Level.SEVERE, "Error while trying to unregister the server from Bukkit. Has Bukkit changed?");
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
main.onDisable();
|
||||
|
||||
MockWorldFactory.clearWorlds();
|
||||
|
||||
deleteFolder(pluginDirectory);
|
||||
deleteFolder(worldsDirectory);
|
||||
deleteFolder(serverDirectory);
|
||||
return true;
|
||||
}
|
||||
|
||||
public JailMain getMain() {
|
||||
return this.main;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return this.mockServer;
|
||||
}
|
||||
|
||||
public CommandSender getCommandSender() {
|
||||
return this.mockSender;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.mockPlayer;
|
||||
}
|
||||
|
||||
public CommandSender getPlayerCommandSender() {
|
||||
return this.mockPlayerSender;
|
||||
}
|
||||
|
||||
private void deleteFolder(File folder) {
|
||||
File[] files = folder.listFiles();
|
||||
if(files != null) {
|
||||
for(File f: files) {
|
||||
if(f.isDirectory()) {
|
||||
deleteFolder(f);
|
||||
}else {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
folder.delete();
|
||||
}
|
||||
}
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftItemFactory;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLogger;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.MockGateway;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.powermock.api.support.membermodification.MemberMatcher.constructor;
|
||||
import static org.powermock.api.support.membermodification.MemberModifier.suppress;
|
||||
|
||||
import com.graywolf336.jail.JailMain;
|
||||
|
||||
@PrepareForTest({ CraftItemFactory.class })
|
||||
public class TestInstanceCreator {
|
||||
private JailMain main;
|
||||
private Server mockServer;
|
||||
private Player mockPlayer;
|
||||
private CommandSender mockSender, mockPlayerSender;
|
||||
private ConsoleCommandSender consoleSender;
|
||||
|
||||
public static final File serverDirectory = new File("bin" + File.separator + "test" + File.separator + "server");
|
||||
public static final File worldsDirectory = new File("bin" + File.separator + "test" + File.separator + "server");
|
||||
public static final File pluginDirectory = new File(serverDirectory + File.separator + "plugins" + File.separator + "JailTest");
|
||||
|
||||
public boolean setup() {
|
||||
try {
|
||||
pluginDirectory.mkdirs();
|
||||
Assert.assertTrue(pluginDirectory.exists());
|
||||
|
||||
MockGateway.MOCK_STANDARD_METHODS = false;
|
||||
|
||||
// Initialize the Mock server.
|
||||
mockServer = mock(Server.class);
|
||||
when(mockServer.getName()).thenReturn("TestBukkit");
|
||||
when(mockServer.getVersion()).thenReturn("Jail-Testing-0.0.1");
|
||||
when(mockServer.getBukkitVersion()).thenReturn("0.0.1");
|
||||
Logger.getLogger("Minecraft").setParent(Util.logger);
|
||||
when(mockServer.getLogger()).thenReturn(Util.logger);
|
||||
when(mockServer.getWorldContainer()).thenReturn(worldsDirectory);
|
||||
when(mockServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
||||
|
||||
MockWorldFactory.makeNewMockWorld("world", Environment.NORMAL, WorldType.NORMAL);
|
||||
|
||||
suppress(constructor(JailMain.class));
|
||||
main = PowerMockito.spy(new JailMain());
|
||||
|
||||
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-Test", "com.graywolf336.jail.JailMain"));
|
||||
when(pdf.getPrefix()).thenReturn("Jail");
|
||||
List<String> authors = new ArrayList<String>();
|
||||
authors.add("matejdro");
|
||||
authors.add("multidude");
|
||||
authors.add("graywolf336");
|
||||
when(pdf.getAuthors()).thenReturn(authors);
|
||||
when(main.getDescription()).thenReturn(pdf);
|
||||
when(main.getDataFolder()).thenReturn(pluginDirectory);
|
||||
when(main.isEnabled()).thenReturn(true);
|
||||
when(main.getLogger()).thenReturn(Util.logger);
|
||||
when(main.getServer()).thenReturn(mockServer);
|
||||
|
||||
Field configFile = JavaPlugin.class.getDeclaredField("configFile");
|
||||
configFile.setAccessible(true);
|
||||
configFile.set(main, new File(pluginDirectory, "config.yml"));
|
||||
|
||||
Field logger = JavaPlugin.class.getDeclaredField("logger");
|
||||
logger.setAccessible(true);
|
||||
logger.set(main, new PluginLogger(main));
|
||||
|
||||
doReturn(getClass().getClassLoader().getResourceAsStream("config.yml")).when(main).getResource("config.yml");
|
||||
doReturn(getClass().getClassLoader().getResourceAsStream("en.yml")).when(main).getResource("en.yml");
|
||||
|
||||
// Add Jail to the list of loaded plugins
|
||||
JavaPlugin[] plugins = new JavaPlugin[] { main };
|
||||
|
||||
// Mock the Plugin Manager
|
||||
PluginManager mockPluginManager = PowerMockito.mock(PluginManager.class);
|
||||
when(mockPluginManager.getPlugins()).thenReturn(plugins);
|
||||
when(mockPluginManager.getPlugin("Jail")).thenReturn(main);
|
||||
when(mockPluginManager.getPermission(anyString())).thenReturn(null);
|
||||
|
||||
// Give the server some worlds
|
||||
when(mockServer.getWorld(anyString())).thenAnswer(new Answer<World>() {
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
String arg;
|
||||
try {
|
||||
arg = (String) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return MockWorldFactory.getWorld(arg);
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getWorld(any(UUID.class))).thenAnswer(new Answer<World>() {
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
UUID arg;
|
||||
try {
|
||||
arg = (UUID) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
return MockWorldFactory.getWorld(arg);
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getWorlds()).thenAnswer(new Answer<List<World>>() {
|
||||
public List<World> answer(InvocationOnMock invocation) throws Throwable {
|
||||
return MockWorldFactory.getWorlds();
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.getPluginManager()).thenReturn(mockPluginManager);
|
||||
|
||||
when(mockServer.createWorld(Matchers.isA(WorldCreator.class))).thenAnswer(
|
||||
new Answer<World>() {
|
||||
public World answer(InvocationOnMock invocation) throws Throwable {
|
||||
WorldCreator arg;
|
||||
try {
|
||||
arg = (WorldCreator) invocation.getArguments()[0];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
// Add special case for creating null worlds.
|
||||
// Not sure I like doing it this way, but this is a special case
|
||||
if (arg.name().equalsIgnoreCase("nullworld")) {
|
||||
return MockWorldFactory.makeNewNullMockWorld(arg.name(), arg.environment(), arg.type());
|
||||
}
|
||||
return MockWorldFactory.makeNewMockWorld(arg.name(), arg.environment(), arg.type());
|
||||
}
|
||||
});
|
||||
|
||||
when(mockServer.unloadWorld(anyString(), anyBoolean())).thenReturn(true);
|
||||
|
||||
// add mock scheduler
|
||||
BukkitScheduler mockScheduler = mock(BukkitScheduler.class);
|
||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class), anyLong())).
|
||||
thenAnswer(new Answer<Integer>() {
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
Runnable arg;
|
||||
try {
|
||||
arg = (Runnable) invocation.getArguments()[1];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
arg.run();
|
||||
return null;
|
||||
}});
|
||||
when(mockScheduler.scheduleSyncDelayedTask(any(Plugin.class), any(Runnable.class))).
|
||||
thenAnswer(new Answer<Integer>() {
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
Runnable arg;
|
||||
try {
|
||||
arg = (Runnable) invocation.getArguments()[1];
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
arg.run();
|
||||
return null;
|
||||
}});
|
||||
when(mockServer.getScheduler()).thenReturn(mockScheduler);
|
||||
|
||||
// Set server
|
||||
Field serverField = JavaPlugin.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(main, mockServer);
|
||||
|
||||
// Init our command sender
|
||||
final Logger consoleSenderLogger = Logger.getLogger("ConsoleCommandSender");
|
||||
consoleSenderLogger.setParent(Util.logger);
|
||||
consoleSender = mock(ConsoleCommandSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
consoleSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
||||
return null;
|
||||
}
|
||||
}).when(consoleSender).sendMessage(anyString());
|
||||
when(consoleSender.getServer()).thenReturn(mockServer);
|
||||
when(consoleSender.getName()).thenReturn("MockCommandSender");
|
||||
when(consoleSender.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(consoleSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(consoleSender.hasPermission(anyString())).thenReturn(true);
|
||||
when(consoleSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(consoleSender.addAttachment(main)).thenReturn(null);
|
||||
when(consoleSender.isOp()).thenReturn(true);
|
||||
when(mockServer.getConsoleSender()).thenReturn(consoleSender);
|
||||
|
||||
// Init our command sender
|
||||
final Logger commandSenderLogger = Logger.getLogger("CommandSender");
|
||||
commandSenderLogger.setParent(Util.logger);
|
||||
mockSender = mock(CommandSender.class);
|
||||
doAnswer(new Answer<Void>() {
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
commandSenderLogger.info(ChatColor.stripColor((String) invocation.getArguments()[0]));
|
||||
return null;
|
||||
}
|
||||
}).when(mockSender).sendMessage(anyString());
|
||||
when(mockSender.getServer()).thenReturn(mockServer);
|
||||
when(mockSender.getName()).thenReturn("MockCommandSender");
|
||||
when(mockSender.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(mockSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockSender.hasPermission(anyString())).thenReturn(true);
|
||||
when(mockSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockSender.addAttachment(main)).thenReturn(null);
|
||||
when(mockSender.isOp()).thenReturn(true);
|
||||
|
||||
// Init our player, who is op and who has all permissions (with name of graywolf336)
|
||||
mockPlayer = mock(Player.class);
|
||||
when(mockPlayer.getUniqueId()).thenReturn(UUID.fromString("062c14ba-4c47-4757-911b-bbf9a60dab7b"));
|
||||
when(mockPlayer.getName()).thenReturn("graywolf336");
|
||||
when(mockPlayer.getDisplayName()).thenReturn("TheGrayWolf");
|
||||
when(mockPlayer.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(mockPlayer.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayer.hasPermission(anyString())).thenReturn(true);
|
||||
when(mockPlayer.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayer.isOp()).thenReturn(true);
|
||||
when(mockPlayer.getInventory()).thenReturn(new MockPlayerInventory());
|
||||
|
||||
// Init our second command sender, but this time is an instance of a player
|
||||
mockPlayerSender = (CommandSender) mockPlayer;
|
||||
when(mockPlayerSender.getServer()).thenReturn(mockServer);
|
||||
when(mockPlayerSender.getName()).thenReturn("graywolf336");
|
||||
when(mockPlayerSender.isPermissionSet(anyString())).thenReturn(true);
|
||||
when(mockPlayerSender.isPermissionSet(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayerSender.hasPermission(anyString())).thenReturn(true);
|
||||
when(mockPlayerSender.hasPermission(Matchers.isA(Permission.class))).thenReturn(true);
|
||||
when(mockPlayerSender.addAttachment(main)).thenReturn(null);
|
||||
when(mockPlayerSender.isOp()).thenReturn(true);
|
||||
|
||||
Bukkit.setServer(mockServer);
|
||||
|
||||
// Load Jail
|
||||
main.onLoad();
|
||||
|
||||
// Enable it and turn on debugging
|
||||
main.onEnable();
|
||||
main.setDebugging(true);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tearDown() {
|
||||
try {
|
||||
Field serverField = Bukkit.class.getDeclaredField("server");
|
||||
serverField.setAccessible(true);
|
||||
serverField.set(Class.forName("org.bukkit.Bukkit"), null);
|
||||
} catch (Exception e) {
|
||||
Util.log(Level.SEVERE, "Error while trying to unregister the server from Bukkit. Has Bukkit changed?");
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
main.onDisable();
|
||||
|
||||
MockWorldFactory.clearWorlds();
|
||||
|
||||
deleteFolder(pluginDirectory);
|
||||
deleteFolder(worldsDirectory);
|
||||
deleteFolder(serverDirectory);
|
||||
return true;
|
||||
}
|
||||
|
||||
public JailMain getMain() {
|
||||
return this.main;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return this.mockServer;
|
||||
}
|
||||
|
||||
public CommandSender getCommandSender() {
|
||||
return this.mockSender;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.mockPlayer;
|
||||
}
|
||||
|
||||
public CommandSender getPlayerCommandSender() {
|
||||
return this.mockPlayerSender;
|
||||
}
|
||||
|
||||
private void deleteFolder(File folder) {
|
||||
File[] files = folder.listFiles();
|
||||
if(files != null) {
|
||||
for(File f: files) {
|
||||
if(f.isDirectory()) {
|
||||
deleteFolder(f);
|
||||
}else {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
folder.delete();
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +1,52 @@
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Util {
|
||||
private Util() {}
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Jail-Test");
|
||||
|
||||
static {
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
Handler handler = new ConsoleHandler();
|
||||
handler.setFormatter(new TestLogFormatter());
|
||||
Handler[] handlers = logger.getHandlers();
|
||||
|
||||
for (Handler h : handlers)
|
||||
logger.removeHandler(h);
|
||||
|
||||
logger.addHandler(handler);
|
||||
}
|
||||
|
||||
public static void log(Throwable t) {
|
||||
log(Level.WARNING, t.getLocalizedMessage(), t);
|
||||
}
|
||||
|
||||
public static void log(Level level, Throwable t) {
|
||||
log(level, t.getLocalizedMessage(), t);
|
||||
}
|
||||
|
||||
public static void log(String message, Throwable t) {
|
||||
log(Level.WARNING, message, t);
|
||||
}
|
||||
|
||||
public static void log(Level level, String message, Throwable t) {
|
||||
LogRecord record = new LogRecord(level, message);
|
||||
record.setThrown(t);
|
||||
logger.log(record);
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
log(Level.INFO, message);
|
||||
}
|
||||
|
||||
public static void log(Level level, String message) {
|
||||
logger.log(level, message);
|
||||
}
|
||||
package test.java.com.graywolf336.jail.util;
|
||||
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Util {
|
||||
private Util() {}
|
||||
|
||||
public static final Logger logger = Logger.getLogger("Jail-Test");
|
||||
|
||||
static {
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
Handler handler = new ConsoleHandler();
|
||||
handler.setFormatter(new TestLogFormatter());
|
||||
Handler[] handlers = logger.getHandlers();
|
||||
|
||||
for (Handler h : handlers)
|
||||
logger.removeHandler(h);
|
||||
|
||||
logger.addHandler(handler);
|
||||
}
|
||||
|
||||
public static void log(Throwable t) {
|
||||
log(Level.WARNING, t.getLocalizedMessage(), t);
|
||||
}
|
||||
|
||||
public static void log(Level level, Throwable t) {
|
||||
log(level, t.getLocalizedMessage(), t);
|
||||
}
|
||||
|
||||
public static void log(String message, Throwable t) {
|
||||
log(Level.WARNING, message, t);
|
||||
}
|
||||
|
||||
public static void log(Level level, String message, Throwable t) {
|
||||
LogRecord record = new LogRecord(level, message);
|
||||
record.setThrown(t);
|
||||
logger.log(record);
|
||||
}
|
||||
|
||||
public static void log(String message) {
|
||||
log(Level.INFO, message);
|
||||
}
|
||||
|
||||
public static void log(Level level, String message) {
|
||||
logger.log(level, message);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user