Permalink
Browse files

Pushing latest dev src for update

  • Loading branch information...
1 parent f7542b0 commit 7bb96dee5c261f0d85de7d888e615a6327d3f764 Blake Bartenbach committed Apr 5, 2013
View
4 org/seed419/founddiamonds/FoundDiamonds.java
@@ -75,10 +75,6 @@
/*
Changelog:
- Re-licensed plugin under GNU GPLv3 (In order to guarantee your freedom to modify, redistribute, and copy!)
- Fixed a few typos in the code..
- Merged trap PR, cleaned it up a bit.
- Improved help in menus
*/
View
4 org/seed419/founddiamonds/Permissions.java
@@ -85,6 +85,10 @@ public boolean hasTrapPerm(CommandSender sender) {
return hasPerm(sender, "fd.trap");
}
+ public boolean hasTrapRemovalPerm(CommandSender sender) {
+ return hasPerm(sender, "fd.trap.remove.self") || hasPerm(sender, "fd.trap.remove.all");
+ }
+
public boolean hasWorldManagementPerm(CommandSender sender) {
return hasPerm(sender, "fd.manage.world");
}
View
114 org/seed419/founddiamonds/Trap.java
@@ -6,11 +6,10 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
-import org.seed419.founddiamonds.util.BlockColor;
+import org.seed419.founddiamonds.handlers.TrapHandler;
import org.seed419.founddiamonds.util.Format;
import org.seed419.founddiamonds.util.Prefix;
-import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -45,8 +44,7 @@
private final Location location; // the 'middle' of the trap
private final Date time; // the date the trap was added;
private boolean persistent; // will the trap persist when broken
- private static ArrayList<Trap> trapList = new ArrayList<Trap>(); // map linking traps to locations, the middle of the trap
- private static Map<Block,Trap> inverseList = new HashMap<Block,Trap>(); // map linking locations to traps
+
public Trap(byte type, Material mat, String player, Location location, boolean persistent) {
@@ -69,6 +67,22 @@ public Trap(byte type, Material mat, Material[] oldMat, String player, Location
trapList.add(this);
this.refillInverse();
}
+
+ public String getPlacer() {
+ return this.placer;
+ }
+
+ public Date getTime() {
+ return this.time;
+ }
+
+ public Location getLocation() {
+ return this.location;
+ }
+
+ public Material getMaterial() {
+ return this.mat;
+ }
private void refillInverse() {
Block[] temp = this.returnLocations(this.location.getWorld());
@@ -131,102 +145,18 @@ public boolean createBlocks() {
case 3:
return new Block[]{this.location.getBlock()}; // emeralds
default:
+ System.out.println("FoundDiamonds: Trap has no type!");
return null; // aliens
}
}
- public void removeTrap() {
- Block[] temp = this.returnLocations(this.location.getWorld());
- for (int i = 0; i < temp.length; i++) {
- temp[i].setType(oldMat[i]);
- inverseList.remove(temp[i]);
- }
- trapList.remove(this);
- }
-
- public static void listTraps(CommandSender sender, int page) { // TODO: Page numbers
- sender.sendMessage(Prefix.getMenuPrefix() + Format.formatMenuHeader("Active Traps"));
- if (trapList.isEmpty()) {
- sender.sendMessage(ChatColor.RED + " None");
- return;
- }
- if (sender.hasPermission("fd.trap.remove.all") || sender.isOp()) {
- if (page >= 0 && ( (page) *5 < trapList.size()) ) { //sane page specified?
- int id1 = (page)*5 ; //begin of the substring
- int id2 = (page +1) *5 -1; //end of the substring
- if (id2 > Trap.trapList.size()) {
- id2 = Trap.trapList.size()-1;
- }
- for (Trap object : trapList) {
- sendTrapListing(sender, object);
- }
- } else {
- sender.sendMessage(ChatColor.RED + "Page number is invalid");
- }
- } else if (sender.hasPermission("fd.trap.remove.self")) { // permission to remove, and thus to see own traps
- ArrayList<Trap> showList = new ArrayList<Trap>();
- for (Trap trap : trapList) {
- if (trap.placer.equals(sender.getName())) {
- showList.add(trap);
- }
- }
- if (page >= 0 && ( (page) *5 < showList.size()) ) { //sane page specified?
- int id1 = (page)*5 ; //begin of the substring
- int id2 = (page +1) *5 -1; //end of the substring
- if (id2 > showList.size()) {
- id2 = showList.size()-1;
- }
- for (Trap object : showList) {
- sendTrapListing(sender, object);
- }
- } else {
- sender.sendMessage(ChatColor.RED + "Page number is invalid");
- }
- } else {
- sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + "You don't have permission to view any traps");
- }
-
- }
-
- private static void sendTrapListing(CommandSender sender, Trap object) {
- sender.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + trapList.indexOf(object) + ChatColor.WHITE + "] "
- + ChatColor.AQUA + DateFormat.getDateInstance(DateFormat.MEDIUM).format((object.time)) + ChatColor.WHITE
- + " @ x" + Format.leftGreenParen + object.location.getBlockX() + Format.rightGreenParen
- + " y" + Format.leftGreenParen + object.location.getBlockY() + Format.rightGreenParen
- + " z" + Format.leftGreenParen + object.location.getBlockZ() + Format.rightGreenParen + " "
- + ChatColor.RED + (object.persistent ? "{Persistent}" : ChatColor.GREEN + "{Breakable}" ));
- sender.sendMessage(" " + BlockColor.getBlockColor(object.mat)
- + Format.capitalize(Format.getFormattedName(object.mat, 1)) + ChatColor.WHITE
- + " placed by " + ChatColor.YELLOW + object.placer + ChatColor.WHITE + " in world "
- + ChatColor.YELLOW + object.location.getWorld().getName());
- }
-
- public static void removeTrapCmd(CommandSender sender, int id) {
- if (id >= 0 && id < trapList.size()) {
- Trap temp = trapList.get(id);
- if ((temp.placer.equals(temp.placer)) &&
- (sender.hasPermission("fd.trap.remove.self") || sender.hasPermission("fd.trap.remove.all"))) {
- temp.removeTrap();
- // TODO this method already exists in TrapHandler
- sender.sendMessage(Prefix.getMenuPrefix() + ChatColor.WHITE + "Trap ID " + ChatColor.WHITE + "["
- + ChatColor.YELLOW + id + ChatColor.WHITE + "]" + ChatColor.GREEN +" removed successfully");
- }
- } else {
- //TODO then what happens?
- }
- }
-
public boolean isPersistent() {
return this.persistent;
}
- public static ArrayList<Trap> getTrapList() {
- return trapList;
- }
-
- public static Map<Block, Trap> getInverseList() {
- return inverseList;
- }
+ public int getID() {
+ return TrapHandler.getTrapList().indexOf(this);
+ }
public String getTrapSummary() { // method to summarize the trap object, for saving
String oldMatString = "";
View
4 org/seed419/founddiamonds/file/FileHandler.java
@@ -72,7 +72,7 @@ public void checkFiles() {
}
}
if (traps.exists()) {
- readTrapsFromFile(traps, fd.getTrapHandler().getTrapBlocks());
+ readTrapsFromFile(traps, fd.getTrapHandler().getTrapList());
}
if (placed.exists() && !fd.getConfig().getBoolean(Config.mysqlEnabled)) {
readBlocksFromFile(placed, fd.getBlockPlaceListener().getFlatFilePlacedBlocks());
@@ -252,7 +252,7 @@ public void readTrapsFromFile(File file, ArrayList<Trap> arrayList) {
public void saveFlatFileData() {
String info = "This file stores your trap block locations.";
- boolean temp = writeTrapsToFile(traps, fd.getTrapHandler().getTrapBlocks(), info);
+ boolean temp = writeTrapsToFile(traps, fd.getTrapHandler().getTrapList(), info);
boolean temp2 = true;
if (!fd.getConfig().getBoolean(Config.mysqlEnabled)) {
String info5 = "This file stores blocks that won't be announced because players placed them.";
View
11 org/seed419/founddiamonds/handlers/MenuHandler.java
@@ -333,17 +333,6 @@ public void handleTrapMenu(FoundDiamonds fd, CommandSender sender, String[] args
if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("s")) {
if (sender instanceof Player) {
Player player = (Player) sender;
-
- // Debugging
-// System.out.println("Args: " + args.length);
-// int counter = 0;
-// for (String x : args) {
-// System.out.print(counter + ": " + x + " ");
-// counter++;
-// }
-// System.out.println();
- // End Debugging
-
fd.getTrapHandler().handleSetTrap(player, args);
} else {
sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " You must be a player to set a trap.");
View
110 org/seed419/founddiamonds/handlers/TrapHandler.java
@@ -14,7 +14,10 @@
import org.seed419.founddiamonds.util.Format;
import org.seed419.founddiamonds.util.Prefix;
+import java.text.DateFormat;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
/*
Copyright 2011-2012 Blake Bartenbach, snoepje0
@@ -39,6 +42,8 @@
private FoundDiamonds fd;
+ private static ArrayList<Trap> trapList = new ArrayList<Trap>(); // map linking traps to locations, the middle of the trap
+ private static Map<Block,Trap> inverseList = new HashMap<Block,Trap>(); // map linking locations to traps
public TrapHandler(FoundDiamonds fd) {
@@ -53,8 +58,8 @@ public void handleSetTrap(CommandSender sender, String[] args) {
Player player = (Player) sender; // MenuHandler verifies this is a player.
if (args[args.length - 1].equalsIgnoreCase("true")) {
persistent = true;
- System.out.println("persisting!");
}
+
if (args.length == 3) {
// either trap block specified with no depth, or depth specified with diamond blocks
// note that the depth will almost *always* match a material ID, so this is NOT recommended.
@@ -98,7 +103,7 @@ public void handleRemoveTrap(CommandSender sender, String[] args) {
if (args.length == 3) {
try {
id = Integer.parseInt(args[2]);
- Trap.removeTrapCmd(sender, id);
+ removeTrapCmd(sender, id);
} catch (NumberFormatException ex) {
sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " Trap ID number must be an integer");
}
@@ -118,7 +123,7 @@ public void handleListTraps(CommandSender sender, String[] args) {
return;
}
}
- Trap.listTraps(sender, page);
+ listTraps(sender, page);
}
private void sendTrapError(Player player) {
@@ -134,9 +139,9 @@ private void createTrap(Player player, Material trapMaterial, int depth, boolean
Trap newTrap = new Trap(getTrapType(trapMaterial), trapMaterial, player.getName(), trapLoc, persistent);
if (newTrap.createBlocks()) {
player.sendMessage(Prefix.getMenuPrefix() + ChatColor.WHITE + "Trap ID [" + ChatColor.YELLOW
- + Trap.getTrapList().size() + ChatColor.WHITE + "] set with " + BlockColor.getBlockColor(trapMaterial)
+ + trapList.size() + ChatColor.WHITE + "] set with " + BlockColor.getBlockColor(trapMaterial)
+ Format.capitalize(Format.getFormattedName(trapMaterial, 1)) + ChatColor.WHITE + getFormattedDepthString(depth));
- Trap.getTrapList().add(newTrap);
+ trapList.add(newTrap);
} else {
player.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " Unable to place a trap here");
player.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " There's another one in the way!");
@@ -200,14 +205,14 @@ private boolean isSensibleTrapBlock(Material trap) {
}
public boolean isTrapBlock(Location loc) {
- return Trap.getInverseList().containsKey(loc.getBlock());
+ return inverseList.containsKey(loc.getBlock());
}
public void handleTrapBlockBreak(BlockBreakEvent event) {
event.setCancelled(true);
Player player = event.getPlayer();
Block block = event.getBlock();
- Trap trap = Trap.getInverseList().get(block);
+ Trap trap = inverseList.get(block);
if (fd.getPermissions().hasPerm(player, "fd.trap")) {
//player.sendMessage(ChatColor.AQUA + "Trap block removed");
sendTrapRemovedMessage(player, trap);
@@ -243,12 +248,93 @@ public void handleTrapBlockBreak(BlockBreakEvent event) {
}
}
- public void sendTrapRemovedMessage(CommandSender sender, Trap trap) {
+ public static void listTraps(CommandSender sender, int page) { // TODO: Page numbers
+ sender.sendMessage(Prefix.getMenuPrefix() + Format.formatMenuHeader("Active Traps"));
+ if (trapList.isEmpty()) {
+ sender.sendMessage(ChatColor.RED + " None");
+ return;
+ }
+ if (sender.hasPermission("fd.trap.remove.all") || sender.isOp()) {
+ if (page >= 0 && ( (page) *5 < trapList.size()) ) { //sane page specified?
+ int id1 = (page)*5 ; //begin of the substring
+ int id2 = (page +1) *5 -1; //end of the substring
+ if (id2 > trapList.size()) {
+ id2 = trapList.size()-1;
+ }
+ for (Trap object : trapList) {
+ TrapHandler.sendTrapListing(sender, object);
+ }
+ } else {
+ sender.sendMessage(ChatColor.RED + "Page number is invalid");
+ }
+ } else if (sender.hasPermission("fd.trap.remove.self")) { // permission to remove, and thus to see own traps
+ ArrayList<Trap> showList = new ArrayList<Trap>();
+ for (Trap trap : trapList) {
+ if (trap.getPlacer().equals(sender.getName())) {
+ showList.add(trap);
+ }
+ }
+ if (page >= 0 && ( (page) *5 < showList.size()) ) { //sane page specified?
+ int id1 = (page)*5 ; //begin of the substring
+ int id2 = (page +1) *5 -1; //end of the substring
+ if (id2 > showList.size()) {
+ id2 = showList.size()-1;
+ }
+ for (Trap object : showList) {
+ TrapHandler.sendTrapListing(sender, object);
+ }
+ } else {
+ sender.sendMessage(ChatColor.RED + "Page number is invalid");
+ }
+ } else {
+ sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + "You don't have permission to view any traps");
+ }
+
+ }
+
+ public static void sendTrapListing(CommandSender sender, Trap trap) {
+ sender.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + trap.getID() + ChatColor.WHITE + "] "
+ + ChatColor.AQUA + DateFormat.getDateInstance(DateFormat.MEDIUM).format((trap.getTime())) + ChatColor.WHITE
+ + " @ x" + Format.leftGreenParen + trap.getLocation().getBlockX() + Format.rightGreenParen
+ + " y" + Format.leftGreenParen + trap.getLocation().getBlockY() + Format.rightGreenParen
+ + " z" + Format.leftGreenParen + trap.getLocation().getBlockZ() + Format.rightGreenParen + " "
+ + ChatColor.RED + (trap.isPersistent() ? "{Persistent}" : ChatColor.GREEN + "{Breakable}" ));
+ sender.sendMessage(" " + BlockColor.getBlockColor(trap.getMaterial())
+ + Format.capitalize(Format.getFormattedName(trap.getMaterial(), 1)) + ChatColor.WHITE
+ + " placed by " + ChatColor.YELLOW + trap.getPlacer() + ChatColor.WHITE + " in world "
+ + ChatColor.YELLOW + trap.getLocation().getWorld().getName());
+ }
+
+ public void removeTrapCmd(CommandSender sender, int id) {
+ if (id >= 0 && id < trapList.size()) {
+ Trap trap = trapList.get(id);
+ if ((trap.getPlacer().equals(sender.getName())) &&
+ (sender.hasPermission("fd.trap.remove.self") || sender.hasPermission("fd.trap.remove.all"))) {
+ Block[] temp = trap.returnLocations(this.location.getWorld());
+ for (int i = 0; i < temp.length; i++) {
+ temp[i].setType(oldMat[i]);
+ inverseList.remove(temp[i]);
+ }
+ trapList.remove(this);
+ sendTrapRemovedMessage(sender, trapList.get(id));
+ }
+ } else {
+ System.out.println("FoundDiamonds: What just happened?");
+ //TODO then what happens?
+ }
+ }
+
+ private void sendTrapRemovedMessage(CommandSender sender, Trap trap) {
sender.sendMessage(Prefix.getMenuPrefix() + ChatColor.WHITE + "Trap ID " + ChatColor.WHITE + "["
- + ChatColor.YELLOW + Trap.getTrapList().indexOf(trap) + ChatColor.WHITE + "]" + ChatColor.GREEN +" removed successfully"); }
+ + ChatColor.YELLOW + trapList.indexOf(trap) + ChatColor.WHITE + "]" + ChatColor.GREEN +" removed successfully");
+ }
- public ArrayList<Trap> getTrapBlocks() {
- return Trap.getTrapList();
- }
+ public ArrayList<Trap> getTrapList() {
+ return trapList;
+ }
+
+ public static Map<Block, Trap> getInverseList() {
+ return inverseList;
+ }
}

0 comments on commit 7bb96de

Please sign in to comment.