First commit, converted to a truely maven project and switching over to my own repository for better management.
This commit is contained in:
commit
596c9de2ad
43
.gitignore
vendored
Normal file
43
.gitignore
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# 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
|
||||||
|
src/com/matejdro/
|
18
README.md
Normal file
18
README.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[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.
|
||||||
|
|
||||||
|
[![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/)
|
||||||
|
|
||||||
|
ToDo
|
||||||
|
===
|
||||||
|
* About everything
|
||||||
|
|
||||||
|
Done
|
||||||
|
===
|
||||||
|
* Muted Prisoners are now muted
|
||||||
|
* New command system, internally we handle commands a lot better
|
||||||
|
* Delete commands are now remove
|
||||||
|
|
||||||
|
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
|
||||||
|
====
|
174
pom.xml
Normal file
174
pom.xml
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
<?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/multidude/Jail</url>
|
||||||
|
<connection>scm:git:git://github.com/multidude/Jail.git</connection>
|
||||||
|
<developerConnection>scm:git:git:@github.com/multidude/Jail.git</developerConnection>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>vault-repo</id>
|
||||||
|
<url>http://ci.herocraftonline.com/plugin/repository/everything</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.6.2-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>
|
||||||
|
|
||||||
|
<!-- Start of Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.8.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-module-junit4</artifactId>
|
||||||
|
<version>1.4.9</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-api-easymock</artifactId>
|
||||||
|
<version>1.4.9</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.powermock</groupId>
|
||||||
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
|
<version>1.4.9</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.easymock</groupId>
|
||||||
|
<artifactId>easymock</artifactId>
|
||||||
|
<version>3.0</version>
|
||||||
|
</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>
|
||||||
|
<directory>${basedir}/src/main/resources/</directory>
|
||||||
|
</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-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>
|
33
src/main/java/com/graywolf336/jail/JailIO.java
Normal file
33
src/main/java/com/graywolf336/jail/JailIO.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
|
public class JailIO {
|
||||||
|
private JailMain pl;
|
||||||
|
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
|
||||||
|
|
||||||
|
public JailIO(JailMain plugin) {
|
||||||
|
this.pl = plugin;
|
||||||
|
|
||||||
|
String st = pl.getConfig().getString("storage.type", "flatfile");
|
||||||
|
if(st.equalsIgnoreCase("sqlite")) {
|
||||||
|
storage = 1;
|
||||||
|
}else if(st.equalsIgnoreCase("mysql")) {
|
||||||
|
storage = 2;
|
||||||
|
}else {
|
||||||
|
storage = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PrepareStorage() {
|
||||||
|
switch(storage) {
|
||||||
|
case 1:
|
||||||
|
//prepare sqlite, I need to research this
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
//prepare mysql, research this as well
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//File system, prepare it somehow.. Maybe load in the files
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
81
src/main/java/com/graywolf336/jail/JailMain.java
Normal file
81
src/main/java/com/graywolf336/jail/JailMain.java
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
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.command.CommandHandler;
|
||||||
|
import com.graywolf336.jail.listeners.BlockListener;
|
||||||
|
import com.graywolf336.jail.listeners.EntityListener;
|
||||||
|
import com.graywolf336.jail.listeners.PlayerListener;
|
||||||
|
import com.graywolf336.jail.listeners.PlayerPreventionsListener;
|
||||||
|
|
||||||
|
public class JailMain extends JavaPlugin {
|
||||||
|
private JailIO io;
|
||||||
|
private JailManager jm;
|
||||||
|
private CommandHandler cmdHand;
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
loadConfig();
|
||||||
|
|
||||||
|
io = new JailIO(this);
|
||||||
|
io.PrepareStorage();
|
||||||
|
|
||||||
|
jm = new JailManager(this);
|
||||||
|
cmdHand = new CommandHandler(this);
|
||||||
|
|
||||||
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
|
pm.registerEvents(new BlockListener(), this);
|
||||||
|
pm.registerEvents(new EntityListener(), this);
|
||||||
|
pm.registerEvents(new PlayerListener(this), this);
|
||||||
|
pm.registerEvents(new PlayerPreventionsListener(this), this);
|
||||||
|
|
||||||
|
//For the time, we will use:
|
||||||
|
//http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/TimeUnit.html#convert(long, java.util.concurrent.TimeUnit)
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
cmdHand = null;
|
||||||
|
jm = null;
|
||||||
|
io = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
//Only create the default config if it doesn't exist
|
||||||
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the {@link JailIO} instance. */
|
||||||
|
public JailIO getJailIO() {
|
||||||
|
return this.io;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the {@link JailManager} instance. */
|
||||||
|
public JailManager getJailManager() {
|
||||||
|
return this.jm;
|
||||||
|
}
|
||||||
|
}
|
269
src/main/java/com/graywolf336/jail/JailManager.java
Normal file
269
src/main/java/com/graywolf336/jail/JailManager.java
Normal file
@ -0,0 +1,269 @@
|
|||||||
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.beans.CreationPlayer;
|
||||||
|
import com.graywolf336.jail.beans.Jail;
|
||||||
|
import com.graywolf336.jail.beans.Prisoner;
|
||||||
|
import com.graywolf336.jail.steps.CellCreationSteps;
|
||||||
|
import com.graywolf336.jail.steps.JailCreationSteps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all things related to jails.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* Stores the following:
|
||||||
|
* <ul>
|
||||||
|
* <li>The {@link Jail jails}, which contains the prisoners and cells.</li>
|
||||||
|
* <li>Players creating jails, see {@link CreationPlayer}.</li>
|
||||||
|
* <li>Players creating jail cells, see {@link CreationPlayer}.</li>
|
||||||
|
* <li>An instance of {@link JailCreationSteps} for stepping players through the Jail creation process.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.1.0
|
||||||
|
*/
|
||||||
|
public class JailManager {
|
||||||
|
private JailMain plugin;
|
||||||
|
private HashMap<String, Jail> jails;
|
||||||
|
private HashMap<String, CreationPlayer> jailCreators;
|
||||||
|
private HashMap<String, CreationPlayer> cellCreators;
|
||||||
|
private JailCreationSteps jcs;
|
||||||
|
private CellCreationSteps ccs;
|
||||||
|
|
||||||
|
public JailManager(JailMain plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.jails = new HashMap<String, Jail>();
|
||||||
|
this.jailCreators = new HashMap<String, CreationPlayer>();
|
||||||
|
this.cellCreators = new HashMap<String, CreationPlayer>();
|
||||||
|
this.jcs = new JailCreationSteps();
|
||||||
|
this.ccs = new CellCreationSteps();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the instance of the plugin main class. */
|
||||||
|
public JailMain getPlugin() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a HashSet of all the jails. */
|
||||||
|
public HashSet<Jail> getJails() {
|
||||||
|
return new HashSet<Jail>(jails.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns an array of all the names of the jails. */
|
||||||
|
public String[] getJailNames() {
|
||||||
|
return this.jails.keySet().toArray(new String[jails.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds a jail to the collection of them. */
|
||||||
|
public void addJail(Jail jail) {
|
||||||
|
this.jails.put(jail.getName(), jail);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a jail by the given name.
|
||||||
|
*
|
||||||
|
* @param name The name of the jail to get.
|
||||||
|
* @return The {@link Jail} with the given name, if no jail found this <strong>will</strong> return null.
|
||||||
|
*/
|
||||||
|
public Jail getJail(String name) {
|
||||||
|
return this.jails.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if the given name for a {@link Jail} is valid, returns true if it is a valid jail.
|
||||||
|
*
|
||||||
|
* @param name The name of the jail to check.
|
||||||
|
* @return True if a valid jail was found, false if no jail was found.
|
||||||
|
*/
|
||||||
|
public boolean isValidJail(String name) {
|
||||||
|
return this.jails.get(name) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Jail jail} the given player is in.
|
||||||
|
*
|
||||||
|
* @param name The name of the player whos jail we are getting.
|
||||||
|
* @return The jail the player is in, <strong>CAN BE NULL</strong>.
|
||||||
|
*/
|
||||||
|
public Jail getJailPlayerIsIn(String name) {
|
||||||
|
Jail re = null;
|
||||||
|
|
||||||
|
for(Jail j : jails.values()) {
|
||||||
|
if(j.isPlayerAPrisoner(name)) {
|
||||||
|
re = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return re;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the given player is jailed or not, in all the jails and cells.
|
||||||
|
*
|
||||||
|
* @param name The name of the player to check.
|
||||||
|
* @return true if they are jailed, false if not.
|
||||||
|
*/
|
||||||
|
public boolean isPlayerJailed(String name) {
|
||||||
|
boolean r = false;
|
||||||
|
|
||||||
|
for(Jail j : jails.values()) {
|
||||||
|
if(j.isPlayerAPrisoner(name)) {
|
||||||
|
r = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link Prisoner} data from for this user, if they are jailed.
|
||||||
|
*
|
||||||
|
* @param name The name of prisoner who's data to get
|
||||||
|
* @return {@link Prisoner prisoner} data.
|
||||||
|
*/
|
||||||
|
public Prisoner getPrisoner(String name) {
|
||||||
|
Jail j = getJailPlayerIsIn(name);
|
||||||
|
|
||||||
|
if(j != null) {
|
||||||
|
return j.getPrisoner(name);
|
||||||
|
}else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether or not the player is creating a jail or a cell.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* If you want to check to see if they're just creating a jail then use {@link #isCreatingAJail(String) isCreatingAJail} or if you want to see if they're creating a cell then use {@link #isCreatingACell(String) isCreatingACell}.
|
||||||
|
*
|
||||||
|
* @param name The name of the player, in any case as we convert it to lowercase.
|
||||||
|
* @return True if the player is creating a jail or cell, false if they're not creating anything.
|
||||||
|
*/
|
||||||
|
public boolean isCreatingSomething(String name) {
|
||||||
|
return this.jailCreators.containsKey(name.toLowerCase()) || this.cellCreators.containsKey(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a message used for telling them what they're creating and what step they're on. */
|
||||||
|
public String getStepMessage(String player) {
|
||||||
|
String message = "";
|
||||||
|
|
||||||
|
if(isCreatingACell(player)) {//Check whether it is a jail cell
|
||||||
|
CreationPlayer cp = this.getCellCreationPlayer(player);
|
||||||
|
message = "You're already creating a Cell with the name '" + cp.getCellName() + "' and you still need to ";
|
||||||
|
|
||||||
|
switch(cp.getStep()) {
|
||||||
|
case 1:
|
||||||
|
message += "set the teleport in location.";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
message += "select all the signs.";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
message += "set the double chest location.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if(isCreatingAJail(player)) {//If not a cell, then check if a jail.
|
||||||
|
CreationPlayer cp = this.getJailCreationPlayer(player);
|
||||||
|
message = "You're already creating a Jail with the name '" + cp.getJailName() + "' and you still need to ";
|
||||||
|
|
||||||
|
switch(cp.getStep()) {
|
||||||
|
case 1:
|
||||||
|
message += "select the first point.";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
message += "select the second point.";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
message += "set the teleport in location.";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
message += "set the release location.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns whether or not someone is creating a <strong>Jail</strong>. */
|
||||||
|
public boolean isCreatingAJail(String name) {
|
||||||
|
return this.jailCreators.containsKey(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for setting a player to be creating a Jail, returns whether or not they were added successfully.
|
||||||
|
*
|
||||||
|
* @param player The player who is creating a jail.
|
||||||
|
* @param jailName The name of the jail we are creating.
|
||||||
|
* @return True if they were added successfully, false if they are already creating a Jail.
|
||||||
|
*/
|
||||||
|
public boolean addCreatingJail(String player, String jailName) {
|
||||||
|
if(isCreatingAJail(player)) {
|
||||||
|
return false;
|
||||||
|
}else {
|
||||||
|
this.jailCreators.put(player.toLowerCase(), new CreationPlayer(jailName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the instance of the CreationPlayer for this player, null if there was none found. */
|
||||||
|
public CreationPlayer getJailCreationPlayer(String name) {
|
||||||
|
return this.jailCreators.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes a CreationPlayer with the given name from the jail creators. */
|
||||||
|
public void removeJailCreationPlayer(String name) {
|
||||||
|
this.jailCreators.remove(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns whether or not someone is creating a <strong>Cell</strong>. */
|
||||||
|
public boolean isCreatingACell(String name) {
|
||||||
|
return this.cellCreators.containsKey(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method for setting a player to be creating a Cell, returns whether or not they were added successfully.
|
||||||
|
*
|
||||||
|
* @param player The player who is creating a jail.
|
||||||
|
* @param jailName The name of the jail this cell is going.
|
||||||
|
* @param cellName The name of the cell we are creating.
|
||||||
|
* @return True if they were added successfully, false if they are already creating a Jail.
|
||||||
|
*/
|
||||||
|
public boolean addCreatingCell(String player, String jailName, String cellName) {
|
||||||
|
if(isCreatingACell(player)) {
|
||||||
|
return false;
|
||||||
|
}else {
|
||||||
|
this.cellCreators.put(player.toLowerCase(), new CreationPlayer(cellName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the instance of the CreationPlayer for this player, null if there was none found. */
|
||||||
|
public CreationPlayer getCellCreationPlayer(String name) {
|
||||||
|
return this.cellCreators.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes a CreationPlayer with the given name from the cell creators. */
|
||||||
|
public void removeCellCreationPlayer(String name) {
|
||||||
|
this.cellCreators.remove(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the instance of the {@link JailCreationSteps}. */
|
||||||
|
public JailCreationSteps getJailCreationSteps() {
|
||||||
|
return this.jcs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the instance of the {@link CellCreationSteps}. */
|
||||||
|
public CellCreationSteps getCellCreationSteps() {
|
||||||
|
return this.ccs;
|
||||||
|
}
|
||||||
|
}
|
38
src/main/java/com/graywolf336/jail/Util.java
Normal file
38
src/main/java/com/graywolf336/jail/Util.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.graywolf336.jail;
|
||||||
|
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
/** Checks if the first {@link Vector} is inside the other two. */
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
95
src/main/java/com/graywolf336/jail/beans/Cell.java
Normal file
95
src/main/java/com/graywolf336/jail/beans/Cell.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package com.graywolf336.jail.beans;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
|
||||||
|
/** Represents a Cell inside of a {@link Jail}.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.1.1
|
||||||
|
*/
|
||||||
|
public class Cell {
|
||||||
|
private String name;
|
||||||
|
private Prisoner p;
|
||||||
|
private HashSet<SimpleLocation> signs;
|
||||||
|
private SimpleLocation teleport, chest;
|
||||||
|
|
||||||
|
public Cell(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.signs = new HashSet<SimpleLocation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the name of the cell. */
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the prisoner in this cell. */
|
||||||
|
public void setPrisoner(Prisoner prisoner) {
|
||||||
|
this.p = prisoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the prisoner being held in this cell. */
|
||||||
|
public Prisoner getPrisoner() {
|
||||||
|
return this.p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePrisoner() {
|
||||||
|
this.p = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if there is currently a prisoner in this cell. */
|
||||||
|
public boolean hasPrisoner() {
|
||||||
|
return this.p != null; //Return true if prison is not null, as when it isn't null we have a prisoner in this cell
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds all the given signs to the cell. */
|
||||||
|
public void addAllSigns(HashSet<SimpleLocation> signs) {
|
||||||
|
this.signs.addAll(signs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds a sign to the cell. */
|
||||||
|
public void addSign(SimpleLocation sign) {
|
||||||
|
this.signs.add(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the location of where the prisoner will be teleported at when jailed here. */
|
||||||
|
public void setTeleport(SimpleLocation location) {
|
||||||
|
this.teleport = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the teleport location where the prisoner will be teleported at when jailed here. */
|
||||||
|
public Location getTeleport() {
|
||||||
|
return this.teleport.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the location of the chest. */
|
||||||
|
public void setChestLocation(Location location) {
|
||||||
|
this.chest = new SimpleLocation(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location of the chest, returns null if no chest is stored at this cell.
|
||||||
|
*
|
||||||
|
* @return The location of the chest, null if none.
|
||||||
|
*/
|
||||||
|
public Location getChestLocation() {
|
||||||
|
return this.chest.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the chest for this cell, returns null if there is no chest or the location we have is not a chest.
|
||||||
|
*
|
||||||
|
* @return The chest and its state.
|
||||||
|
*/
|
||||||
|
public Chest getChest() {
|
||||||
|
if(this.chest == null) return null;
|
||||||
|
if((this.chest.getLocation().getBlock() == null) || (this.chest.getLocation().getBlock().getType() != Material.CHEST)) return null;
|
||||||
|
|
||||||
|
return (Chest) this.chest.getLocation().getBlock().getState();
|
||||||
|
}
|
||||||
|
}
|
227
src/main/java/com/graywolf336/jail/beans/CreationPlayer.java
Normal file
227
src/main/java/com/graywolf336/jail/beans/CreationPlayer.java
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
package com.graywolf336.jail.beans;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an instance of a player creating something, whether it be a jail or cell.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.1.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CreationPlayer {
|
||||||
|
private String jailName, cellName;
|
||||||
|
private int step;
|
||||||
|
private int x1, y1, z1, x2, y2, z2;
|
||||||
|
private String inWorld, freeWorld;
|
||||||
|
private double inX, inY, inZ, freeX, freeY, freeZ;
|
||||||
|
private float inPitch, inYaw, freePitch, freeYaw;
|
||||||
|
private HashSet<SimpleLocation> signs;
|
||||||
|
private Location chest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of a CreationPlayer, given the name of the jail.
|
||||||
|
*
|
||||||
|
* @param jailName The name of the jail.
|
||||||
|
*/
|
||||||
|
public CreationPlayer(String jailName) {
|
||||||
|
this.jailName = jailName;
|
||||||
|
this.step = 1; //Set the default to 1 when creating this.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of a CreationPlayer, give the name of the jail and cell.
|
||||||
|
*
|
||||||
|
* @param jailName The name of the jail.
|
||||||
|
* @param cellName The name of the cell.
|
||||||
|
*/
|
||||||
|
public CreationPlayer(String jailName, String cellName) {
|
||||||
|
this.jailName = jailName;
|
||||||
|
this.cellName = cellName;
|
||||||
|
this.signs = new HashSet<SimpleLocation>();
|
||||||
|
this.step = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the name of the jail. */
|
||||||
|
public String getJailName() {
|
||||||
|
return this.jailName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the name of the cell. */
|
||||||
|
public String getCellName() {
|
||||||
|
return this.cellName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the step the creation is in.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* If it is a <strong>Jail</strong>, then when these numbers are returned it means the following:
|
||||||
|
* <ol>
|
||||||
|
* <li>Creating the first block of the Jail region.</li>
|
||||||
|
* <li>Creating the second block of the Jail region.</li>
|
||||||
|
* <li>Creating the teleport in location.</li>
|
||||||
|
* <li>Creating the teleport out location.</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* If it is a <strong>Cell</strong>, then when these numbers are returned it means the following:
|
||||||
|
* <ol>
|
||||||
|
* <li>Setting the teleport in location.</li>
|
||||||
|
* <li>Setting all the signs.</li>
|
||||||
|
* <li>Setting the double chest.</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @return The step of the Jail/Cell Creation, as an integer.
|
||||||
|
*/
|
||||||
|
public int getStep() {
|
||||||
|
return this.step;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the step of the creation.
|
||||||
|
*
|
||||||
|
* @param step The state of the creation, see {@link #getStep() getStep} for more information.
|
||||||
|
*/
|
||||||
|
public void setStep(int step) {
|
||||||
|
this.step = step;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the current step up one.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* <em>Notice:</em> Using this method can cause the step to go above four (three for cell),
|
||||||
|
* which might cause errors later on. Only use when you know that it won't
|
||||||
|
* be used again or you know for a fact that the next step is not above four (three for cell).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void nextStep() {
|
||||||
|
this.step++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the first corner with the given location. */
|
||||||
|
public void setCornerOne(Location loc) {
|
||||||
|
this.x1 = loc.getBlockX();
|
||||||
|
this.y1 = loc.getBlockY();
|
||||||
|
this.z1 = loc.getBlockZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the first corner with the given x, y, and z. */
|
||||||
|
public void setCornerOne(int x, int y, int z) {
|
||||||
|
this.x1 = x;
|
||||||
|
this.y1 = y;
|
||||||
|
this.z1 = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the <strong>first corner</strong> coords an array of int. <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong> */
|
||||||
|
public int[] getCornerOne() {
|
||||||
|
int[] t = {x1, y1, z1};
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the second corner with the given location. */
|
||||||
|
public void setCornerTwo(Location loc) {
|
||||||
|
this.x2 = loc.getBlockX();
|
||||||
|
this.y2 = loc.getBlockY();
|
||||||
|
this.z2 = loc.getBlockZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the second corner with the given x, y, and z. */
|
||||||
|
public void setCornerTwo(int x, int y, int z) {
|
||||||
|
this.x2 = x;
|
||||||
|
this.y2 = y;
|
||||||
|
this.z2 = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the <strong>second corner</strong> coords an array of int. <strong>0 = x</strong>, <strong>1 = y</strong>, <strong>2 = z</strong> */
|
||||||
|
public int[] getCornerTwo() {
|
||||||
|
int[] t = {x2, y2, z2};
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the teleport in coords from the given location. */
|
||||||
|
public void setTeleportIn(Location location) {
|
||||||
|
this.inWorld = location.getWorld().getName();
|
||||||
|
this.inX = location.getX();
|
||||||
|
this.inY = location.getY();
|
||||||
|
this.inZ = location.getZ();
|
||||||
|
this.inYaw = location.getYaw();
|
||||||
|
this.inPitch = location.getPitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the teleport in coords from the given params. */
|
||||||
|
public void setTeleportIn(String world, double x, double y, double z, float yaw, float pitch) {
|
||||||
|
this.inWorld = world;
|
||||||
|
this.inX = x;
|
||||||
|
this.inY = y;
|
||||||
|
this.inZ = z;
|
||||||
|
this.inYaw = yaw;
|
||||||
|
this.inPitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the teleport in location in a {@link Location}. */
|
||||||
|
public Location getTeleportIn() {
|
||||||
|
return new Location(Bukkit.getWorld(inWorld), inX, inY, inZ, inYaw, inPitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the teleport in location in a {@link SimpleLocation}. */
|
||||||
|
public SimpleLocation getTeleportInSL() {
|
||||||
|
return new SimpleLocation(inWorld, inX, inY, inZ, inYaw, inPitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the teleport free coords from the given location. */
|
||||||
|
public void setTeleportFree(Location location) {
|
||||||
|
this.freeWorld = location.getWorld().getName();
|
||||||
|
this.freeX = location.getX();
|
||||||
|
this.freeY = location.getY();
|
||||||
|
this.freeZ = location.getZ();
|
||||||
|
this.freeYaw = location.getYaw();
|
||||||
|
this.freePitch = location.getPitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the teleport in coords from the given params. */
|
||||||
|
public void setTeleportFree(String world, double x, double y, double z, float yaw, float pitch) {
|
||||||
|
this.freeWorld = world;
|
||||||
|
this.freeX = x;
|
||||||
|
this.freeY = y;
|
||||||
|
this.freeZ = z;
|
||||||
|
this.freeYaw = yaw;
|
||||||
|
this.freePitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the teleport free location in a {@link Location}. */
|
||||||
|
public Location getTeleportFree() {
|
||||||
|
return new Location(Bukkit.getWorld(freeWorld), freeX, freeY, freeZ, freeYaw, freePitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the teleport free location in a {@link SimpleLocation}. */
|
||||||
|
public SimpleLocation getTeleportFreeSL() {
|
||||||
|
return new SimpleLocation(freeWorld, freeX, freeY, freeZ, freeYaw, freePitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds a sign to this cell. */
|
||||||
|
public void addSign(SimpleLocation sign) {
|
||||||
|
this.signs.add(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns all the signs, null if none (usually null when a jail is being created). */
|
||||||
|
public HashSet<SimpleLocation> getSigns() {
|
||||||
|
return this.signs == null ? null : new HashSet<SimpleLocation>(this.signs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the chest's location, used mainly for cells. */
|
||||||
|
public void setChestLocation(Location loc) {
|
||||||
|
this.chest = loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the chest's location. */
|
||||||
|
public Location getChestLocation() {
|
||||||
|
return this.chest;
|
||||||
|
}
|
||||||
|
}
|
231
src/main/java/com/graywolf336/jail/beans/Jail.java
Normal file
231
src/main/java/com/graywolf336/jail/beans/Jail.java
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
package com.graywolf336.jail.beans;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailMain;
|
||||||
|
|
||||||
|
/** Represents a Jail, contains the prisoners and the cells.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.0.2
|
||||||
|
*/
|
||||||
|
public class Jail {
|
||||||
|
private JailMain plugin;
|
||||||
|
private HashMap<String, Cell> cells;
|
||||||
|
private HashSet<Prisoner> nocellPrisoners;//prisoners who aren't in a cell
|
||||||
|
private String name = "", world = "";
|
||||||
|
private int minX, minY, minZ, maxX, maxY, maxZ;
|
||||||
|
private SimpleLocation in, free;
|
||||||
|
|
||||||
|
public Jail(JailMain plugin, String name) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.name = name;
|
||||||
|
cells = new HashMap<String, Cell>();
|
||||||
|
nocellPrisoners = new HashSet<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(Bukkit.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(Bukkit.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 {@link SimpleLocation location} of the teleport <strong>in</strong>. */
|
||||||
|
public void setTeleportIn(SimpleLocation location) {
|
||||||
|
if(this.world.isEmpty()) this.world = location.getWorldName();
|
||||||
|
|
||||||
|
this.in = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the {@link Location location} of the teleport in. */
|
||||||
|
public Location getTeleportIn() {
|
||||||
|
return this.in.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the {@link SimpleLocation location} of the teleport for the <strong>free</strong> spot. */
|
||||||
|
public void setTeleportFree(SimpleLocation location) {
|
||||||
|
this.free = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the {@link Location location} of the teleport free spot.*/
|
||||||
|
public Location getTeleportFree() {
|
||||||
|
return this.free.getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds a cell to the Jail. */
|
||||||
|
public void addCell(Cell cell) {
|
||||||
|
this.cells.put(cell.getName(), cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the cell with the given name. */
|
||||||
|
public Cell getCell(String name) {
|
||||||
|
return this.cells.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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 a HashSet of <b>all</b> the prisoners, the ones in cells and ones who aren't. */
|
||||||
|
public HashSet<Prisoner> getAllPrisoners() {
|
||||||
|
HashSet<Prisoner> all = new HashSet<Prisoner>(nocellPrisoners); //initalize the temp one to return with the prisoners not in any cells
|
||||||
|
|
||||||
|
for(Cell c : cells.values())
|
||||||
|
if(c.hasPrisoner())
|
||||||
|
all.add(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 HashSet<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.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the name of a player is a prisoner in the system, whether in a cell or no cell.
|
||||||
|
*
|
||||||
|
* @param name The name of the person we're checking.
|
||||||
|
* @return true if is jailed, false if not.
|
||||||
|
*/
|
||||||
|
public boolean isPlayerJailed(String name) {
|
||||||
|
return this.isPlayerAPrisoner(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the name of a player is a prisoner in the system, whether in a cell or no cell.
|
||||||
|
*
|
||||||
|
* @param name The name of the person we're checking.
|
||||||
|
* @return true if is a prisoner, false if not.
|
||||||
|
*/
|
||||||
|
public boolean isPlayerAPrisoner(String name) {
|
||||||
|
boolean is = false;
|
||||||
|
|
||||||
|
for(Prisoner p : this.getAllPrisoners()) {
|
||||||
|
if(p.getName().equalsIgnoreCase(name)) {
|
||||||
|
is = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 getPrisoner(String name) {
|
||||||
|
Prisoner r = null;
|
||||||
|
|
||||||
|
for(Prisoner p : this.getAllPrisoners()) {
|
||||||
|
if(p.getName().equalsIgnoreCase(name)) {
|
||||||
|
r = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
32
src/main/java/com/graywolf336/jail/beans/Prisoner.java
Normal file
32
src/main/java/com/graywolf336/jail/beans/Prisoner.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.graywolf336.jail.beans;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Prisoner, player who is jailed, and contains all the information about him/her.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 2.x.x
|
||||||
|
* @version 2.0.0
|
||||||
|
*/
|
||||||
|
public class Prisoner {
|
||||||
|
private String name;
|
||||||
|
private boolean muted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new prisoner with a name and whether they are muted or not.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param muted
|
||||||
|
*/
|
||||||
|
public Prisoner(String name, boolean muted) {
|
||||||
|
this.name = name;
|
||||||
|
this.muted = muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMuted() {
|
||||||
|
return this.muted;
|
||||||
|
}
|
||||||
|
}
|
48
src/main/java/com/graywolf336/jail/beans/SimpleLocation.java
Normal file
48
src/main/java/com/graywolf336/jail/beans/SimpleLocation.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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.0
|
||||||
|
*/
|
||||||
|
public class SimpleLocation {
|
||||||
|
private String world;
|
||||||
|
private double x, y, z;
|
||||||
|
private float yaw, pitch;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return Bukkit.getWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWorldName() {
|
||||||
|
return this.world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/com/graywolf336/jail/command/Command.java
Normal file
31
src/main/java/com/graywolf336/jail/command/Command.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.graywolf336.jail.command;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base of all the commands.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public interface Command {
|
||||||
|
/**
|
||||||
|
* Execute the command given the arguments, returning whether the command handled it or not.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* When the method returns false, the usage message is printed to the sender. If the method
|
||||||
|
* handles the command in any way, such as sending a message to the sender or actually doing
|
||||||
|
* something, then it should return true so that the sender of the command doesn't get the
|
||||||
|
* usage message.
|
||||||
|
*
|
||||||
|
* @param jm An instance of the {@link JailManager}
|
||||||
|
* @param sender The {@link CommandSender sender} of the command
|
||||||
|
* @param args The args, in an array
|
||||||
|
* @return True if the method handled it in any way, false if we should send the usage message.
|
||||||
|
*/
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args);
|
||||||
|
}
|
157
src/main/java/com/graywolf336/jail/command/CommandHandler.java
Normal file
157
src/main/java/com/graywolf336/jail/command/CommandHandler.java
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
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.CellCreateCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailCheckCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailClearCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailCreateCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailRemoveCellCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailStopCommand;
|
||||||
|
import com.graywolf336.jail.command.commands.JailVersionCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.getLogger().info("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 command The name of the command.
|
||||||
|
* @param args The arguments passed to the command.
|
||||||
|
*/
|
||||||
|
public void handleCommand(JailManager jailmanager, CommandSender sender, String command, String[] args) {
|
||||||
|
List<Command> matches = getMatches(command);
|
||||||
|
|
||||||
|
if(matches.size() == 0) {
|
||||||
|
sender.sendMessage("No commands registered by the name of " + command + ".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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("No permission to use that command.");//TODO: Make this configurable
|
||||||
|
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("A player context is required for this command.");
|
||||||
|
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.
|
||||||
|
if(!c.execute(jailmanager, sender, args)) {
|
||||||
|
showUsage(sender, c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(CellCreateCommand.class);
|
||||||
|
load(JailCheckCommand.class);
|
||||||
|
load(JailClearCommand.class);
|
||||||
|
load(JailCommand.class);
|
||||||
|
load(JailCreateCommand.class);
|
||||||
|
load(JailRemoveCellCommand.class);
|
||||||
|
load(JailStopCommand.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
75
src/main/java/com/graywolf336/jail/command/CommandInfo.java
Normal file
75
src/main/java/com/graywolf336/jail/command/CommandInfo.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package com.graywolf336.jail.command;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains a definition of all the annotations {@link Command commands} should have, if a {@link Command command} doesn't have any then it isn't registered.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* This helps make loading and registering and verifying commands a lot
|
||||||
|
* easier, makes sure that before we really process a command that it
|
||||||
|
* is structured correctly and all the right information is passed. If
|
||||||
|
* the command takes a variety of options, then that command obviously
|
||||||
|
* has to handle it. We just max sure that the minimum amount of
|
||||||
|
* arguments is met and same with the maximum amount, if there is a max.
|
||||||
|
* We also check if the commands needs a player or not, if so and the
|
||||||
|
* sender is something other than a player we send a message stating that
|
||||||
|
* a player context is required. The pattern is just used to match up
|
||||||
|
* the command used to it's registered value, in regex form. We check
|
||||||
|
* the permission stated and determine if the sender has it or not, if
|
||||||
|
* they don't then we send a message stating they don't have permission
|
||||||
|
* for that command. Finally we have the usage string, which is sent
|
||||||
|
* when the sender of the command sends an incorrectly formatted
|
||||||
|
* command. The order of checking is as defined in {@link CommandHandler#handleCommand(com.graywolf336.jail.JailManager, org.bukkit.command.CommandSender, String, String[]) CommandHandler.handleCommand}.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.0.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Retention (RetentionPolicy.RUNTIME)
|
||||||
|
public @interface CommandInfo {
|
||||||
|
/**
|
||||||
|
* Gets the maximum amount of arguments required, -1 if no maximum (ex: Jailing someone with a reason or editing a reason).
|
||||||
|
*
|
||||||
|
* @return The maximum number of arguments required, -1 if no maximum.
|
||||||
|
*/
|
||||||
|
public int maxArgs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the minimum amount of arguments required.
|
||||||
|
*
|
||||||
|
* @return The minimum number of arguments required.
|
||||||
|
*/
|
||||||
|
public int minimumArgs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the command needs a player context or not.
|
||||||
|
*
|
||||||
|
* @return True if requires a player, false if not.
|
||||||
|
*/
|
||||||
|
public boolean needsPlayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A regex pattern that allows for alternatives to the command (ex: /jail or /j, /jailstatus or /js).
|
||||||
|
*
|
||||||
|
* @return The regex pattern to match.
|
||||||
|
*/
|
||||||
|
public String pattern();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the permission required to execute this command.
|
||||||
|
*
|
||||||
|
* @return The permission required.
|
||||||
|
*/
|
||||||
|
public String permission();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the usage message for this command.
|
||||||
|
*
|
||||||
|
* @return The usage message.
|
||||||
|
*/
|
||||||
|
public String usage();
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
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.Cell;
|
||||||
|
import com.graywolf336.jail.beans.Jail;
|
||||||
|
import com.graywolf336.jail.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = 2,
|
||||||
|
minimumArgs = 2,
|
||||||
|
needsPlayer = true,
|
||||||
|
pattern = "jailcreatecells|jcc",
|
||||||
|
permission = "jail.command.jailcreatecells",
|
||||||
|
usage = "/jailcellcreate [jail] [cellname]"
|
||||||
|
)
|
||||||
|
public class CellCreateCommand implements Command {
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String name = player.getName();
|
||||||
|
String jail = args[0].toLowerCase();
|
||||||
|
String cell = args[1];
|
||||||
|
|
||||||
|
//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);
|
||||||
|
Cell c = j.getCell(cell);
|
||||||
|
|
||||||
|
//No cell found
|
||||||
|
if(c == 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.graywolf336.jail.command.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
import com.graywolf336.jail.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = 1,
|
||||||
|
minimumArgs = 0,
|
||||||
|
needsPlayer = true,
|
||||||
|
pattern = "jailcheck|jcheck",
|
||||||
|
permission = "jail.command.jailcheck",
|
||||||
|
usage = "/jailcheck (Player name)"
|
||||||
|
)
|
||||||
|
public class JailCheckCommand implements Command{
|
||||||
|
|
||||||
|
// Checks the status of the specified prisoner, if no args, will display all players currently jailed
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
return true; //If they made it this far, the command is intact and ready to be processed. :)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.graywolf336.jail.command.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
import com.graywolf336.jail.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = 1,
|
||||||
|
minimumArgs = 0,
|
||||||
|
needsPlayer = false,
|
||||||
|
pattern = "jailclear|jclear",
|
||||||
|
permission = "jail.command.jailclear",
|
||||||
|
usage = "/jailclear (Jail name)"
|
||||||
|
)
|
||||||
|
public class JailClearCommand implements Command {
|
||||||
|
|
||||||
|
// If Jail is specified clear all prisoners from that Jail (new feature) else, clear all players from all jails
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
return true; //If they made it this far, the command is intact and ready to be processed. :)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.graywolf336.jail.command.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
import com.graywolf336.jail.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = -1,
|
||||||
|
minimumArgs = 1,
|
||||||
|
needsPlayer = false,
|
||||||
|
pattern = "jail|j",
|
||||||
|
permission = "jail.command.jail",
|
||||||
|
usage = "/jail [name] (time) (j:Jail name) (c:Cell name) (r:Reason) (m:Muted)"
|
||||||
|
)
|
||||||
|
public class JailCommand implements Command {
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
return true; //If they made it this far, the command is intact and ready to be processed. :)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
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.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = 1,
|
||||||
|
minimumArgs = 1,
|
||||||
|
needsPlayer = true,
|
||||||
|
pattern = "jailcreate|jc",
|
||||||
|
permission = "jail.command.jailcreate",
|
||||||
|
usage = "/jailcreate [name]"
|
||||||
|
)
|
||||||
|
public class JailCreateCommand implements Command {
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String name = player.getName();
|
||||||
|
String jail = args[0];
|
||||||
|
|
||||||
|
//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 {
|
||||||
|
if(jm.isValidJail(jail)) {
|
||||||
|
player.sendMessage(ChatColor.RED + "Jail by the name of '" + jail + "' already exist!");
|
||||||
|
}else {
|
||||||
|
if(jm.addCreatingJail(name, jail)) {
|
||||||
|
jm.getJailCreationSteps().startStepping(player);
|
||||||
|
}else {
|
||||||
|
player.sendMessage(ChatColor.RED + "Seems like you're already creating a Jail or something went wrong on our side.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.graywolf336.jail.command.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
import com.graywolf336.jail.command.Command;
|
||||||
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
|
|
||||||
|
@CommandInfo(
|
||||||
|
maxArgs = 2,
|
||||||
|
minimumArgs = 1,
|
||||||
|
needsPlayer = true,
|
||||||
|
pattern = "jailremovecell|jrcell",
|
||||||
|
permission = "jail.command.jailremovecell",
|
||||||
|
usage = "/jailremovecell [Jail Name] (Cell Name)"
|
||||||
|
)
|
||||||
|
public class JailRemoveCellCommand implements Command{
|
||||||
|
|
||||||
|
// Remove the specified Cell from the Specified Jail, if no cell specified will delete nearest cell
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
return true; //If they made it this far, the command is intact and ready to be processed. :)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.graywolf336.jail.command.commands;
|
||||||
|
|
||||||
|
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 = true,
|
||||||
|
pattern = "jailstop",
|
||||||
|
permission = "jail.command.jailstop",
|
||||||
|
usage = "/jailstop"
|
||||||
|
)
|
||||||
|
public class JailStopCommand implements Command {
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
jm.removeJailCreationPlayer(sender.getName());
|
||||||
|
jm.removeCellCreationPlayer(sender.getName());
|
||||||
|
|
||||||
|
sender.sendMessage("Any creations, jail or cell, have been stopped.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.graywolf336.jail.command.commands;
|
||||||
|
|
||||||
|
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 = "jailversion|jv",
|
||||||
|
permission = "jail.command.jailversion",
|
||||||
|
usage = "/jailversion"
|
||||||
|
)
|
||||||
|
public class JailVersionCommand implements Command{
|
||||||
|
|
||||||
|
public boolean execute(JailManager jm, CommandSender sender, String... args) {
|
||||||
|
// Sends the version number to the sender
|
||||||
|
sender.sendMessage("Jail Version: " + jm.getPlugin().getDescription().getVersion());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.graywolf336.jail.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event thrown when a player is fixing to be jailed, both offline and online players.
|
||||||
|
*
|
||||||
|
* 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 0.0.0
|
||||||
|
*/
|
||||||
|
public class PrisonerJailedEvent {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.graywolf336.jail.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event thrown when a player is being released from jail, both offline and online players.
|
||||||
|
*
|
||||||
|
* This event is called whenever a player is being released from jail whether the player is offline or online, getPlayer() will always return null if isOnline() return false.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 0.0.0
|
||||||
|
*/
|
||||||
|
public class PrisonerReleasedEvent {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.graywolf336.jail.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class BlockListener implements Listener {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.graywolf336.jail.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class EntityListener implements Listener {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.graywolf336.jail.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailMain;
|
||||||
|
import com.graywolf336.jail.JailManager;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener {
|
||||||
|
private JailMain pl;
|
||||||
|
|
||||||
|
public PlayerListener(JailMain plugin) {
|
||||||
|
this.pl = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
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(jm.isCreatingSomething(p.getName())) {
|
||||||
|
if(jm.isCreatingAJail(p.getName())) {
|
||||||
|
|
||||||
|
jm.getJailCreationSteps().step(jm, p, jm.getJailCreationPlayer(p.getName()), loc);
|
||||||
|
|
||||||
|
}else if(jm.isCreatingACell(p.getName())) {
|
||||||
|
|
||||||
|
//One for jail cell creation
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void chatting(AsyncPlayerChatEvent event) {
|
||||||
|
if(pl.getJailManager().isPlayerJailed(event.getPlayer().getName())) {
|
||||||
|
if(pl.getJailManager().getPrisoner(event.getPlayer().getName()).isMuted()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.getPlayer().sendMessage(ChatColor.RED + "Stop talking, you're currently jailed and muted.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.graywolf336.jail.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailMain;
|
||||||
|
import com.graywolf336.jail.beans.Jail;
|
||||||
|
|
||||||
|
public class PlayerPreventionsListener implements Listener {
|
||||||
|
private JailMain pl;
|
||||||
|
|
||||||
|
public PlayerPreventionsListener(JailMain plugin) {
|
||||||
|
this.pl = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void preventChat(AsyncPlayerChatEvent event) {
|
||||||
|
if(event.isCancelled()) return;
|
||||||
|
|
||||||
|
Jail j = pl.getJailManager().getJailPlayerIsIn(event.getPlayer().getName());
|
||||||
|
|
||||||
|
if(j != null) {
|
||||||
|
event.setCancelled(j.getPrisoner(event.getPlayer().getName()).isMuted());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
135
src/main/java/com/graywolf336/jail/steps/CellCreationSteps.java
Normal file
135
src/main/java/com/graywolf336/jail/steps/CellCreationSteps.java
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
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.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.0
|
||||||
|
*/
|
||||||
|
public class CellCreationSteps {
|
||||||
|
|
||||||
|
/** Sends the Cell Creation message for starting out. */
|
||||||
|
public void startStepping(Player player){
|
||||||
|
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
|
||||||
|
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 + "----------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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 ----------");
|
||||||
|
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 ----------");
|
||||||
|
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 ----------");
|
||||||
|
player.sendMessage(ChatColor.GREEN + "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();
|
||||||
|
|
||||||
|
if (block.getType() == Material.CHEST) {
|
||||||
|
if(bpos1 == Material.CHEST || bpos2 == Material.CHEST || bpos3 == Material.CHEST || bpos4 == Material.CHEST) {
|
||||||
|
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 + "Chest must be a double chest, chest not selected");
|
||||||
|
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());
|
||||||
|
c.setChestLocation(cp.getChestLocation());
|
||||||
|
|
||||||
|
j.addCell(c);
|
||||||
|
|
||||||
|
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 /jailstop.");
|
||||||
|
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
|
||||||
|
}
|
||||||
|
}
|
133
src/main/java/com/graywolf336/jail/steps/JailCreationSteps.java
Normal file
133
src/main/java/com/graywolf336/jail/steps/JailCreationSteps.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package com.graywolf336.jail.steps;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
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.0
|
||||||
|
*/
|
||||||
|
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 + "--------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
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());
|
||||||
|
jail.setTeleportFree(cp.getTeleportFreeSL());
|
||||||
|
|
||||||
|
jm.addJail(jail);
|
||||||
|
|
||||||
|
p.sendMessage(ChatColor.GREEN + "Jail (" + jail.getName() + ") created successfully!");
|
||||||
|
|
||||||
|
jm.removeJailCreationPlayer(p.getName());
|
||||||
|
}
|
||||||
|
}
|
11
src/main/resources/config.yml
Normal file
11
src/main/resources/config.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
system:
|
||||||
|
configVersion: 3
|
||||||
|
debug: false
|
||||||
|
updateNotifications: true
|
||||||
|
storage:
|
||||||
|
type: 'flatfile' #can be flatfile, sqlite, or mysql
|
||||||
|
mysql:
|
||||||
|
host: 'localhost'
|
||||||
|
port: 3306
|
||||||
|
username: 'root'
|
||||||
|
password: 'password'
|
191
src/main/resources/plugin.yml
Normal file
191
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
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: [Spout, WorldEdit, Vault, Notifications]
|
||||||
|
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 [player name] (time) (jail name):(cell name) (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
|
||||||
|
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.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
|
@ -0,0 +1,102 @@
|
|||||||
|
package test.java.com.graywolf336.jail;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
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 TestJailCommandInfo {
|
||||||
|
private TestInstanceCreator creator;
|
||||||
|
private JailMain main;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
creator = new TestInstanceCreator();
|
||||||
|
assertTrue(creator.setup());
|
||||||
|
main = creator.getMain();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
creator.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidCommand() {
|
||||||
|
Command command = mock(Command.class);
|
||||||
|
when(command.getName()).thenReturn("thisisnotavalidcommand");
|
||||||
|
String[] args = {};
|
||||||
|
|
||||||
|
CommandSender sender = creator.getCommandSender();
|
||||||
|
|
||||||
|
assertTrue(main.onCommand(sender, command, "thisisnotavalidcommand", args));
|
||||||
|
verify(sender).sendMessage("No commands registered by the name of thisisnotavalidcommand.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testForPlayerContext() {
|
||||||
|
Command command = mock(Command.class);
|
||||||
|
when(command.getName()).thenReturn("jailcreate");
|
||||||
|
String[] args = { "testJail" };
|
||||||
|
|
||||||
|
CommandSender sender = creator.getCommandSender();
|
||||||
|
|
||||||
|
assertTrue(main.onCommand(sender, command, "jailcreate", args));
|
||||||
|
verify(sender).sendMessage("A player context is required for this command.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinimumArgs() {
|
||||||
|
Command command = mock(Command.class);
|
||||||
|
when(command.getName()).thenReturn("jailcreate");
|
||||||
|
String[] args = {};
|
||||||
|
|
||||||
|
CommandSender sender = creator.getPlayerCommandSender();
|
||||||
|
|
||||||
|
assertTrue(main.onCommand(sender, command, "jailcreate", args));
|
||||||
|
verify(sender).sendMessage("/jailcreate [name]"); // If you change which command we test against, then change this
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaximumArgs() {
|
||||||
|
Command command = mock(Command.class);
|
||||||
|
when(command.getName()).thenReturn("jailcreate");
|
||||||
|
String[] args = { "testing", "badarg", "reallyterribleone" };
|
||||||
|
|
||||||
|
CommandSender sender = creator.getPlayerCommandSender();
|
||||||
|
|
||||||
|
assertTrue(main.onCommand(sender, command, "jailcreate", args));
|
||||||
|
verify(sender).sendMessage("/jailcreate [name]"); // If you change which command we test against, then change this
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccessfulJailCreateCommand() {
|
||||||
|
Command command = mock(Command.class);
|
||||||
|
when(command.getName()).thenReturn("jailcreate");
|
||||||
|
String[] args = { "testJail" };
|
||||||
|
|
||||||
|
CommandSender sender = creator.getPlayerCommandSender();
|
||||||
|
|
||||||
|
assertTrue(main.onCommand(sender, command, "jailcreate", args));
|
||||||
|
verify(sender).sendMessage(ChatColor.AQUA + "----------Jail Zone Creation----------");
|
||||||
|
verify(sender).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!");
|
||||||
|
verify(sender).sendMessage(ChatColor.AQUA + "--------------------------------------");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
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.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
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 TestInstanceCreator creator;
|
||||||
|
private JailMain main;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
creator = new TestInstanceCreator();
|
||||||
|
creator.setup();
|
||||||
|
main = creator.getMain();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
creator.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testForJails() {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package test.java.com.graywolf336.jail;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.Util;
|
||||||
|
|
||||||
|
public class TestVectorsInside {
|
||||||
|
private Vector bottomCorner;
|
||||||
|
private Vector topCorner;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
bottomCorner = new Vector(-10.50, 50.25, 100.00);
|
||||||
|
topCorner = new Vector(50, 100, 250);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
bottomCorner = null;
|
||||||
|
topCorner = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsInsideAB() {
|
||||||
|
Vector inside = new Vector(35, 64, 110);
|
||||||
|
assertTrue(Util.isInsideAB(inside, bottomCorner, topCorner));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsOutsideAB() {
|
||||||
|
Vector outside = new Vector(350, 15, 350);
|
||||||
|
assertFalse(Util.isInsideAB(outside, bottomCorner, topCorner));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHalfInHalfOutsideAB() {
|
||||||
|
Vector halfAndHalf = new Vector(25, 75, 99);
|
||||||
|
assertFalse(Util.isInsideAB(halfAndHalf, bottomCorner, topCorner));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,214 @@
|
|||||||
|
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>() {
|
||||||
|
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>() {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,280 @@
|
|||||||
|
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.WorldCreator;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
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 static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.JailMain;
|
||||||
|
|
||||||
|
public class TestInstanceCreator {
|
||||||
|
private JailMain main;
|
||||||
|
private Server mockServer;
|
||||||
|
private Player mockPlayer;
|
||||||
|
private CommandSender mockSender, mockPlayerSender;
|
||||||
|
|
||||||
|
public static final File pluginDirectory = new File("bin/test/server/plugins/JailTest");
|
||||||
|
public static final File serverDirectory = new File("bin/test/server");
|
||||||
|
public static final File worldsDirectory = new File("bin/test/server");
|
||||||
|
|
||||||
|
public boolean setup() {
|
||||||
|
try {
|
||||||
|
pluginDirectory.mkdirs();
|
||||||
|
Assert.assertTrue(pluginDirectory.exists());
|
||||||
|
|
||||||
|
MockGateway.MOCK_STANDARD_METHODS = false;
|
||||||
|
|
||||||
|
main = PowerMockito.spy(new JailMain());
|
||||||
|
|
||||||
|
doReturn(pluginDirectory).when(main).getDataFolder();
|
||||||
|
|
||||||
|
PluginDescriptionFile pdf = PowerMockito.spy(new PluginDescriptionFile("Jail", "3.0.0-Test", "com.graywolf336.jail.JailMain"));
|
||||||
|
List<String> authors = new ArrayList<String>();
|
||||||
|
authors.add("matejdro");
|
||||||
|
authors.add("multidude");
|
||||||
|
authors.add("graywolf336");
|
||||||
|
when(pdf.getAuthors()).thenReturn(authors);
|
||||||
|
doReturn(pdf).when(main).getDescription();
|
||||||
|
doReturn(true).when(main).isEnabled();
|
||||||
|
doReturn(Util.logger).when(main).getLogger();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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 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.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);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
main.onEnable();
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package test.java.com.graywolf336.jail.util;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
|
/** Formatter to format log-messages in tests */
|
||||||
|
public class TestLogFormatter extends Formatter {
|
||||||
|
private static final DateFormat df = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
||||||
|
public String format(LogRecord record) {
|
||||||
|
StringBuilder ret = new StringBuilder();
|
||||||
|
|
||||||
|
ret.append("[").append(df.format(record.getMillis())).append("] [")
|
||||||
|
.append(record.getLoggerName()).append("] [")
|
||||||
|
.append(record.getLevel().getLocalizedName()).append("] ");
|
||||||
|
ret.append(record.getMessage());
|
||||||
|
ret.append('\n');
|
||||||
|
|
||||||
|
if (record.getThrown() != null) {
|
||||||
|
// An Exception was thrown! Let's print the StackTrace!
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
record.getThrown().printStackTrace(new PrintWriter(writer));
|
||||||
|
ret.append(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.toString();
|
||||||
|
}
|
||||||
|
}
|
52
src/test/java/test/java/com/graywolf336/jail/util/Util.java
Normal file
52
src/test/java/test/java/com/graywolf336/jail/util/Util.java
Normal file
@ -0,0 +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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user