Give the players a wand when starting to create a jail or cell.

This commit is contained in:
graywolf336 2013-12-06 15:56:46 -06:00
parent 647a4f9d17
commit e07c657a40
4 changed files with 319 additions and 278 deletions

View File

@ -1,5 +1,11 @@
package com.graywolf336.jail; package com.graywolf336.jail;
import java.util.LinkedList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class Util { public class Util {
@ -40,4 +46,17 @@ public class Util {
public static String getColorfulMessage(String message) { public static String getColorfulMessage(String message) {
return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1"); return message.replaceAll("(?i)&([0-9abcdefklmnor])", "\u00A7$1");
} }
public static ItemStack getWand() {
ItemStack wand = new ItemStack(Material.WOOD_SWORD);
ItemMeta meta = wand.getItemMeta();
meta.setDisplayName(ChatColor.AQUA + "Jail Wand");
LinkedList<String> lore = new LinkedList<String>();
lore.add(ChatColor.BLUE + "The wand for creating");
lore.add(ChatColor.BLUE + "a jail or cell.");
meta.setLore(lore);
wand.setItemMeta(meta);
return wand;
}
} }

View File

@ -1,135 +1,145 @@
package com.graywolf336.jail.steps; package com.graywolf336.jail.steps;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.graywolf336.jail.JailManager; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.Util; import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.Cell; import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.CreationPlayer; import com.graywolf336.jail.beans.CreationPlayer;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.SimpleLocation; import com.graywolf336.jail.beans.SimpleLocation;
/** /**
* Class for stepping a player through the Cell creation process, instance is stored in {@link JailManager}. * Class for stepping a player through the Cell creation process, instance is stored in {@link JailManager}.
* *
* @author graywolf336 * @author graywolf336
* @since 3.0.0 * @since 3.0.0
* @version 1.0.0 * @version 1.0.1
*/ */
public class CellCreationSteps { public class CellCreationSteps {
/** Sends the Cell Creation message for starting out. */ /** Sends the Cell Creation message for starting out. */
public void startStepping(Player player){ public void startStepping(Player player){
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------"); 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.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 + "----------------------------------------"); player.sendMessage(ChatColor.AQUA + "----------------------------------------");
}
if(player.getInventory().contains(Material.WOOD_SWORD)) {
/** int i = player.getInventory().first(Util.getWand());
* Applies the next step in the Cell Creation process that involves a location, null if no location is needed. if(i != -1) {
* player.getInventory().setItem(i, player.getItemInHand());
* @param jm The {@link JailManager} instance. player.setItemInHand(Util.getWand());
* @param player The player who is doing the creating. }
* @param cp The {@link CreationPlayer} instance }else {
* @param location The location, null if none, being set. player.getInventory().addItem(Util.getWand());
*/ }
public void step(JailManager jm, Player player, CreationPlayer cp, Location location) { }
switch(cp.getStep()) {
case 1: /**
firstStep(jm, cp, player); * Applies the next step in the Cell Creation process that involves a location, null if no location is needed.
break; *
case 2: * @param jm The {@link JailManager} instance.
secondStep(cp, player, location.getBlock()); * @param player The player who is doing the creating.
break; * @param cp The {@link CreationPlayer} instance
case 3: * @param location The location, null if none, being set.
thirdStep(jm, cp, player, location.getBlock()); */
break; public void step(JailManager jm, Player player, CreationPlayer cp, Location location) {
default: switch(cp.getStep()) {
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over"); case 1:
jm.removeJailCreationPlayer(player.getName()); firstStep(jm, cp, player);
break; break;
} case 2:
} secondStep(cp, player, location.getBlock());
break;
/** Applies the first step, which is setting the teleport in location. */ case 3:
private void firstStep(JailManager jm, CreationPlayer cp, Player player) { thirdStep(jm, cp, player, location.getBlock());
Vector v1 = jm.getJail(cp.getJailName()).getMinPoint().toVector().clone(); break;
Vector v2 = jm.getJail(cp.getJailName()).getMaxPoint().toVector().clone(); default:
Vector point = player.getLocation().toVector().clone(); player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over");
jm.removeJailCreationPlayer(player.getName());
if(Util.isInsideAB(point, v1, v2)) { break;
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 + "----------------------------------------");
/** Applies the first step, which is setting the teleport in location. */
cp.setTeleportIn(player.getLocation()); private void firstStep(JailManager jm, CreationPlayer cp, Player player) {
cp.nextStep(); Vector v1 = jm.getJail(cp.getJailName()).getMinPoint().toVector().clone();
}else { Vector v2 = jm.getJail(cp.getJailName()).getMaxPoint().toVector().clone();
player.sendMessage(ChatColor.RED + "---------- Jail Cell Creation ----------"); Vector point = player.getLocation().toVector().clone();
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 + "----------------------------------------"); 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 + "----------------------------------------");
/** Applies the second step, which is adding signs to the cell. */
private void secondStep(CreationPlayer cp, Player player, Block block) { cp.setTeleportIn(player.getLocation());
if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) { cp.nextStep();
cp.addSign(new SimpleLocation(block.getLocation())); }else {
player.sendMessage(ChatColor.GREEN + "Sign added, if you want to select another go ahead otherwise right click on any non-sign block."); player.sendMessage(ChatColor.RED + "---------- Jail Cell Creation ----------");
}else { 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.AQUA + "---------- Jail Cell Creation ----------"); player.sendMessage(ChatColor.RED + "----------------------------------------");
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 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) {
/** Applies the third step, which is adding a chest or select not to have a chest. */ cp.addSign(new SimpleLocation(block.getLocation()));
private void thirdStep(JailManager jm, CreationPlayer cp, Player player, Block block) { player.sendMessage(ChatColor.GREEN + "Sign added, if you want to select another go ahead otherwise right click on any non-sign block.");
Material bpos1 = block.getLocation().add(-1, 0, 0).getBlock().getType(); }else {
Material bpos2 = block.getLocation().add(+1, 0, 0).getBlock().getType(); player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
Material bpos3 = block.getLocation().add(0, 0, -1).getBlock().getType(); 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.)");
Material bpos4 = block.getLocation().add(0, 0, +1).getBlock().getType(); player.sendMessage(ChatColor.AQUA + "----------------------------------------");
cp.nextStep();
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 ----------"); /** Applies the third step, which is adding a chest or select not to have a chest. */
player.sendMessage(ChatColor.GREEN + "Chest selected."); private void thirdStep(JailManager jm, CreationPlayer cp, Player player, Block block) {
player.sendMessage(ChatColor.AQUA + "----------------------------------------"); Material bpos1 = block.getLocation().add(-1, 0, 0).getBlock().getType();
}else { Material bpos2 = block.getLocation().add(+1, 0, 0).getBlock().getType();
player.sendMessage(ChatColor.RED + "Chest must be a double chest, chest not selected"); Material bpos3 = block.getLocation().add(0, 0, -1).getBlock().getType();
return; Material bpos4 = block.getLocation().add(0, 0, +1).getBlock().getType();
}
}else { if (block.getType() == Material.CHEST) {
player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------"); if(bpos1 == Material.CHEST || bpos2 == Material.CHEST || bpos3 == Material.CHEST || bpos4 == Material.CHEST) {
player.sendMessage(ChatColor.RED + "No chest selected."); cp.setChestLocation(block.getLocation());
player.sendMessage(ChatColor.AQUA + "----------------------------------------"); player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
} player.sendMessage(ChatColor.GREEN + "Chest selected.");
player.sendMessage(ChatColor.AQUA + "----------------------------------------");
finalStep(jm, cp, player); }else {
} player.sendMessage(ChatColor.RED + "Chest must be a double chest, chest not selected");
return;
private void finalStep(JailManager jm, CreationPlayer cp, Player player) { }
Jail j = jm.getJail(cp.getJailName()); }else {
Cell c = new Cell(cp.getCellName()); player.sendMessage(ChatColor.AQUA + "---------- Jail Cell Creation ----------");
player.sendMessage(ChatColor.RED + "No chest selected.");
c.addAllSigns(cp.getSigns()); player.sendMessage(ChatColor.AQUA + "----------------------------------------");
c.setTeleport(cp.getTeleportInSL()); }
c.setChestLocation(cp.getChestLocation());
finalStep(jm, cp, player);
j.addCell(c); }
jm.removeCellCreationPlayer(player.getName()); private void finalStep(JailManager jm, CreationPlayer cp, Player player) {
jm.addCreatingCell(player.getName(), j.getName(), "cell_n" + (j.getCellCount() + 1)); Jail j = jm.getJail(cp.getJailName());
Cell c = new Cell(cp.getCellName());
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."); c.addAllSigns(cp.getSigns());
player.sendMessage(ChatColor.AQUA + "----------------------------------------"); 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 + "----------------------------------------");
}
}

View File

@ -1,133 +1,144 @@
package com.graywolf336.jail.steps; package com.graywolf336.jail.steps;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.Material;
import org.bukkit.util.Vector; import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.Util; import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.CreationPlayer; import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.Jail; 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}. /**
* * Class for stepping a player through the Jail creation process, instance is stored in {@link JailManager}.
* @author graywolf336 *
* @since 3.0.0 * @author graywolf336
* @version 1.1.0 * @since 3.0.0
*/ * @version 1.1.1
public class JailCreationSteps { */
public class JailCreationSteps {
/** Sends the Jail Creation message for starting out. */
public void startStepping(Player player) { /** Sends the Jail Creation message for starting out. */
player.sendMessage(ChatColor.AQUA + "----------Jail Zone Creation----------"); public void startStepping(Player player) {
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 + "----------Jail Zone Creation----------");
player.sendMessage(ChatColor.AQUA + "--------------------------------------"); 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 + "--------------------------------------");
/** if(player.getInventory().contains(Material.WOOD_SWORD)) {
* Applies the next step in the Jail Creation process that involves a location, null if no location is needed. int i = player.getInventory().first(Util.getWand());
* if(i != -1) {
* @param jm The {@link JailManager} instance. player.getInventory().setItem(i, player.getItemInHand());
* @param player The player who is doing the creating. player.setItemInHand(Util.getWand());
* @param cp The {@link CreationPlayer} instance }
* @param location The location, null if none, being set. }else {
*/ player.getInventory().addItem(Util.getWand());
public void step(JailManager jm, Player player, CreationPlayer cp, Location location) { }
switch(cp.getStep()) { }
case 1:
firstStep(cp, player, location); /**
break; * Applies the next step in the Jail Creation process that involves a location, null if no location is needed.
case 2: *
secondStep(cp, player, location); * @param jm The {@link JailManager} instance.
break; * @param player The player who is doing the creating.
case 3: * @param cp The {@link CreationPlayer} instance
thirdStep(cp, player); * @param location The location, null if none, being set.
break; */
case 4: public void step(JailManager jm, Player player, CreationPlayer cp, Location location) {
fourthStep(jm, cp, player); switch(cp.getStep()) {
break; case 1:
default: firstStep(cp, player, location);
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over"); break;
jm.removeJailCreationPlayer(player.getName()); case 2:
break; secondStep(cp, player, location);
} break;
} case 3:
thirdStep(cp, player);
/** Applies the first step, which is setting the first corner. */ break;
private void firstStep(CreationPlayer cp, Player p, Location location) { case 4:
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation----------"); fourthStep(jm, cp, player);
p.sendMessage(ChatColor.GREEN + "First point selected. Now select the second point."); break;
p.sendMessage(ChatColor.AQUA + "---------------------------------------"); default:
player.sendMessage(ChatColor.RED + "Something went wrong with the creation of the Jail, please start over");
cp.setCornerOne(location); jm.removeJailCreationPlayer(player.getName());
cp.nextStep(); break;
} }
}
/** Applies the second step, which is setting the second corner. */
private void secondStep(CreationPlayer cp, Player p, Location location) { /** Applies the first step, which is setting the first corner. */
p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation ----------"); private void firstStep(CreationPlayer cp, Player p, Location location) {
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 + "---------- Jail Zone Creation----------");
p.sendMessage(ChatColor.AQUA + "----------------------------------------"); p.sendMessage(ChatColor.GREEN + "First point selected. Now select the second point.");
p.sendMessage(ChatColor.AQUA + "---------------------------------------");
cp.setCornerTwo(location);
cp.nextStep(); cp.setCornerOne(location);
} cp.nextStep();
}
/** Applies the third step, which is setting the teleport in location. */
private void thirdStep(CreationPlayer cp, Player p) { /** Applies the second step, which is setting the second corner. */
private void secondStep(CreationPlayer cp, Player p, Location location) {
int[] p1 = cp.getCornerOne(); p.sendMessage(ChatColor.AQUA + "---------- Jail Zone Creation ----------");
int[] p2 = cp.getCornerTwo(); 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.");
Vector v1 = new Vector(p1[0], p1[1], p1[2]); p.sendMessage(ChatColor.AQUA + "----------------------------------------");
Vector v2 = new Vector(p2[0], p2[1], p2[2]);
Vector point = p.getLocation().toVector().clone(); cp.setCornerTwo(location);
cp.nextStep();
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."); /** Applies the third step, which is setting the teleport in location. */
p.sendMessage(ChatColor.AQUA + "----------------------------------------"); private void thirdStep(CreationPlayer cp, Player p) {
cp.setTeleportIn(p.getLocation()); int[] p1 = cp.getCornerOne();
cp.nextStep(); int[] p2 = cp.getCornerTwo();
} else { Vector v1 = new Vector(p1[0], p1[1], p1[2]);
p.sendMessage(ChatColor.RED + "---------- Jail Zone Creation ----------"); Vector v2 = new Vector(p2[0], p2[1], p2[2]);
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."); Vector point = p.getLocation().toVector().clone();
p.sendMessage(ChatColor.RED + "----------------------------------------");
} 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.");
private void fourthStep(JailManager jm, CreationPlayer cp, Player p) { p.sendMessage(ChatColor.AQUA + "----------------------------------------");
int[] p1 = cp.getCornerOne();
int[] p2 = cp.getCornerTwo(); cp.setTeleportIn(p.getLocation());
Vector v1 = new Vector(p1[0], p1[1], p1[2]); cp.nextStep();
Vector v2 = new Vector(p2[0], p2[1], p2[2]); } else {
Vector point = p.getLocation().toVector().clone(); 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.");
if(Util.isInsideAB(point, v1, v2)) { p.sendMessage(ChatColor.RED + "----------------------------------------");
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 { private void fourthStep(JailManager jm, CreationPlayer cp, Player p) {
cp.setTeleportFree(p.getLocation()); int[] p1 = cp.getCornerOne();
int[] p2 = cp.getCornerTwo();
finalStep(jm, cp, p); 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();
private void finalStep(JailManager jm, CreationPlayer cp, Player p) { if(Util.isInsideAB(point, v1, v2)) {
Jail jail = new Jail(jm.getPlugin(), cp.getJailName()); 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.");
jail.setMinPoint(cp.getCornerOne()); p.sendMessage(ChatColor.RED + "----------------------------------------");
jail.setMaxPoint(cp.getCornerTwo()); }else {
jail.setTeleportIn(cp.getTeleportInSL()); cp.setTeleportFree(p.getLocation());
jail.setTeleportFree(cp.getTeleportFreeSL());
finalStep(jm, cp, p);
jm.addJail(jail); }
}
p.sendMessage(ChatColor.GREEN + "Jail (" + jail.getName() + ") created successfully!");
private void finalStep(JailManager jm, CreationPlayer cp, Player p) {
jm.removeJailCreationPlayer(p.getName()); 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());
}
}

View File

@ -1,11 +1,12 @@
system: system:
configVersion: 3 configVersion: 3
debug: false debug: false
updateNotifications: true language: 'en'
storage: updateNotifications: true
type: 'flatfile' #can be flatfile, sqlite, or mysql storage:
mysql: type: 'flatfile' #can be flatfile, sqlite, or mysql
host: 'localhost' mysql:
port: 3306 host: 'localhost'
username: 'root' port: 3306
username: 'root'
password: 'password' password: 'password'