Skip to content
This repository
Browse code

Pushing latest dev src for update

  • Loading branch information...
commit 7bb96dee5c261f0d85de7d888e615a6327d3f764 1 parent f7542b0
Blake Bartenbach authored
4 org/seed419/founddiamonds/FoundDiamonds.java
@@ -75,10 +75,6 @@
75 75
76 76 /*
77 77 Changelog:
78   - Re-licensed plugin under GNU GPLv3 (In order to guarantee your freedom to modify, redistribute, and copy!)
79   - Fixed a few typos in the code..
80   - Merged trap PR, cleaned it up a bit.
81   - Improved help in menus
82 78 */
83 79
84 80
4 org/seed419/founddiamonds/Permissions.java
@@ -85,6 +85,10 @@ public boolean hasTrapPerm(CommandSender sender) {
85 85 return hasPerm(sender, "fd.trap");
86 86 }
87 87
  88 + public boolean hasTrapRemovalPerm(CommandSender sender) {
  89 + return hasPerm(sender, "fd.trap.remove.self") || hasPerm(sender, "fd.trap.remove.all");
  90 + }
  91 +
88 92 public boolean hasWorldManagementPerm(CommandSender sender) {
89 93 return hasPerm(sender, "fd.manage.world");
90 94 }
114 org/seed419/founddiamonds/Trap.java
@@ -6,11 +6,10 @@
6 6 import org.bukkit.World;
7 7 import org.bukkit.block.Block;
8 8 import org.bukkit.command.CommandSender;
9   -import org.seed419.founddiamonds.util.BlockColor;
  9 +import org.seed419.founddiamonds.handlers.TrapHandler;
10 10 import org.seed419.founddiamonds.util.Format;
11 11 import org.seed419.founddiamonds.util.Prefix;
12 12
13   -import java.text.DateFormat;
14 13 import java.util.ArrayList;
15 14 import java.util.Date;
16 15 import java.util.HashMap;
@@ -45,8 +44,7 @@
45 44 private final Location location; // the 'middle' of the trap
46 45 private final Date time; // the date the trap was added;
47 46 private boolean persistent; // will the trap persist when broken
48   - private static ArrayList<Trap> trapList = new ArrayList<Trap>(); // map linking traps to locations, the middle of the trap
49   - private static Map<Block,Trap> inverseList = new HashMap<Block,Trap>(); // map linking locations to traps
  47 +
50 48
51 49
52 50 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
69 67 trapList.add(this);
70 68 this.refillInverse();
71 69 }
  70 +
  71 + public String getPlacer() {
  72 + return this.placer;
  73 + }
  74 +
  75 + public Date getTime() {
  76 + return this.time;
  77 + }
  78 +
  79 + public Location getLocation() {
  80 + return this.location;
  81 + }
  82 +
  83 + public Material getMaterial() {
  84 + return this.mat;
  85 + }
72 86
73 87 private void refillInverse() {
74 88 Block[] temp = this.returnLocations(this.location.getWorld());
@@ -131,102 +145,18 @@ public boolean createBlocks() {
131 145 case 3:
132 146 return new Block[]{this.location.getBlock()}; // emeralds
133 147 default:
  148 + System.out.println("FoundDiamonds: Trap has no type!");
134 149 return null; // aliens
135 150 }
136 151 }
137 152
138   - public void removeTrap() {
139   - Block[] temp = this.returnLocations(this.location.getWorld());
140   - for (int i = 0; i < temp.length; i++) {
141   - temp[i].setType(oldMat[i]);
142   - inverseList.remove(temp[i]);
143   - }
144   - trapList.remove(this);
145   - }
146   -
147   - public static void listTraps(CommandSender sender, int page) { // TODO: Page numbers
148   - sender.sendMessage(Prefix.getMenuPrefix() + Format.formatMenuHeader("Active Traps"));
149   - if (trapList.isEmpty()) {
150   - sender.sendMessage(ChatColor.RED + " None");
151   - return;
152   - }
153   - if (sender.hasPermission("fd.trap.remove.all") || sender.isOp()) {
154   - if (page >= 0 && ( (page) *5 < trapList.size()) ) { //sane page specified?
155   - int id1 = (page)*5 ; //begin of the substring
156   - int id2 = (page +1) *5 -1; //end of the substring
157   - if (id2 > Trap.trapList.size()) {
158   - id2 = Trap.trapList.size()-1;
159   - }
160   - for (Trap object : trapList) {
161   - sendTrapListing(sender, object);
162   - }
163   - } else {
164   - sender.sendMessage(ChatColor.RED + "Page number is invalid");
165   - }
166   - } else if (sender.hasPermission("fd.trap.remove.self")) { // permission to remove, and thus to see own traps
167   - ArrayList<Trap> showList = new ArrayList<Trap>();
168   - for (Trap trap : trapList) {
169   - if (trap.placer.equals(sender.getName())) {
170   - showList.add(trap);
171   - }
172   - }
173   - if (page >= 0 && ( (page) *5 < showList.size()) ) { //sane page specified?
174   - int id1 = (page)*5 ; //begin of the substring
175   - int id2 = (page +1) *5 -1; //end of the substring
176   - if (id2 > showList.size()) {
177   - id2 = showList.size()-1;
178   - }
179   - for (Trap object : showList) {
180   - sendTrapListing(sender, object);
181   - }
182   - } else {
183   - sender.sendMessage(ChatColor.RED + "Page number is invalid");
184   - }
185   - } else {
186   - sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + "You don't have permission to view any traps");
187   - }
188   -
189   - }
190   -
191   - private static void sendTrapListing(CommandSender sender, Trap object) {
192   - sender.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + trapList.indexOf(object) + ChatColor.WHITE + "] "
193   - + ChatColor.AQUA + DateFormat.getDateInstance(DateFormat.MEDIUM).format((object.time)) + ChatColor.WHITE
194   - + " @ x" + Format.leftGreenParen + object.location.getBlockX() + Format.rightGreenParen
195   - + " y" + Format.leftGreenParen + object.location.getBlockY() + Format.rightGreenParen
196   - + " z" + Format.leftGreenParen + object.location.getBlockZ() + Format.rightGreenParen + " "
197   - + ChatColor.RED + (object.persistent ? "{Persistent}" : ChatColor.GREEN + "{Breakable}" ));
198   - sender.sendMessage(" " + BlockColor.getBlockColor(object.mat)
199   - + Format.capitalize(Format.getFormattedName(object.mat, 1)) + ChatColor.WHITE
200   - + " placed by " + ChatColor.YELLOW + object.placer + ChatColor.WHITE + " in world "
201   - + ChatColor.YELLOW + object.location.getWorld().getName());
202   - }
203   -
204   - public static void removeTrapCmd(CommandSender sender, int id) {
205   - if (id >= 0 && id < trapList.size()) {
206   - Trap temp = trapList.get(id);
207   - if ((temp.placer.equals(temp.placer)) &&
208   - (sender.hasPermission("fd.trap.remove.self") || sender.hasPermission("fd.trap.remove.all"))) {
209   - temp.removeTrap();
210   - // TODO this method already exists in TrapHandler
211   - sender.sendMessage(Prefix.getMenuPrefix() + ChatColor.WHITE + "Trap ID " + ChatColor.WHITE + "["
212   - + ChatColor.YELLOW + id + ChatColor.WHITE + "]" + ChatColor.GREEN +" removed successfully");
213   - }
214   - } else {
215   - //TODO then what happens?
216   - }
217   - }
218   -
219 153 public boolean isPersistent() {
220 154 return this.persistent;
221 155 }
222 156
223   - public static ArrayList<Trap> getTrapList() {
224   - return trapList;
225   - }
226   -
227   - public static Map<Block, Trap> getInverseList() {
228   - return inverseList;
229   - }
  157 + public int getID() {
  158 + return TrapHandler.getTrapList().indexOf(this);
  159 + }
230 160
231 161 public String getTrapSummary() { // method to summarize the trap object, for saving
232 162 String oldMatString = "";
4 org/seed419/founddiamonds/file/FileHandler.java
@@ -72,7 +72,7 @@ public void checkFiles() {
72 72 }
73 73 }
74 74 if (traps.exists()) {
75   - readTrapsFromFile(traps, fd.getTrapHandler().getTrapBlocks());
  75 + readTrapsFromFile(traps, fd.getTrapHandler().getTrapList());
76 76 }
77 77 if (placed.exists() && !fd.getConfig().getBoolean(Config.mysqlEnabled)) {
78 78 readBlocksFromFile(placed, fd.getBlockPlaceListener().getFlatFilePlacedBlocks());
@@ -252,7 +252,7 @@ public void readTrapsFromFile(File file, ArrayList<Trap> arrayList) {
252 252
253 253 public void saveFlatFileData() {
254 254 String info = "This file stores your trap block locations.";
255   - boolean temp = writeTrapsToFile(traps, fd.getTrapHandler().getTrapBlocks(), info);
  255 + boolean temp = writeTrapsToFile(traps, fd.getTrapHandler().getTrapList(), info);
256 256 boolean temp2 = true;
257 257 if (!fd.getConfig().getBoolean(Config.mysqlEnabled)) {
258 258 String info5 = "This file stores blocks that won't be announced because players placed them.";
11 org/seed419/founddiamonds/handlers/MenuHandler.java
@@ -333,17 +333,6 @@ public void handleTrapMenu(FoundDiamonds fd, CommandSender sender, String[] args
333 333 if (args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("s")) {
334 334 if (sender instanceof Player) {
335 335 Player player = (Player) sender;
336   -
337   - // Debugging
338   -// System.out.println("Args: " + args.length);
339   -// int counter = 0;
340   -// for (String x : args) {
341   -// System.out.print(counter + ": " + x + " ");
342   -// counter++;
343   -// }
344   -// System.out.println();
345   - // End Debugging
346   -
347 336 fd.getTrapHandler().handleSetTrap(player, args);
348 337 } else {
349 338 sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " You must be a player to set a trap.");
110 org/seed419/founddiamonds/handlers/TrapHandler.java
@@ -14,7 +14,10 @@
14 14 import org.seed419.founddiamonds.util.Format;
15 15 import org.seed419.founddiamonds.util.Prefix;
16 16
  17 +import java.text.DateFormat;
17 18 import java.util.ArrayList;
  19 +import java.util.HashMap;
  20 +import java.util.Map;
18 21
19 22 /*
20 23 Copyright 2011-2012 Blake Bartenbach, snoepje0
@@ -39,6 +42,8 @@
39 42
40 43
41 44 private FoundDiamonds fd;
  45 + private static ArrayList<Trap> trapList = new ArrayList<Trap>(); // map linking traps to locations, the middle of the trap
  46 + private static Map<Block,Trap> inverseList = new HashMap<Block,Trap>(); // map linking locations to traps
42 47
43 48
44 49 public TrapHandler(FoundDiamonds fd) {
@@ -53,8 +58,8 @@ public void handleSetTrap(CommandSender sender, String[] args) {
53 58 Player player = (Player) sender; // MenuHandler verifies this is a player.
54 59 if (args[args.length - 1].equalsIgnoreCase("true")) {
55 60 persistent = true;
56   - System.out.println("persisting!");
57 61 }
  62 +
58 63 if (args.length == 3) {
59 64 // either trap block specified with no depth, or depth specified with diamond blocks
60 65 // 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) {
98 103 if (args.length == 3) {
99 104 try {
100 105 id = Integer.parseInt(args[2]);
101   - Trap.removeTrapCmd(sender, id);
  106 + removeTrapCmd(sender, id);
102 107 } catch (NumberFormatException ex) {
103 108 sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " Trap ID number must be an integer");
104 109 }
@@ -118,7 +123,7 @@ public void handleListTraps(CommandSender sender, String[] args) {
118 123 return;
119 124 }
120 125 }
121   - Trap.listTraps(sender, page);
  126 + listTraps(sender, page);
122 127 }
123 128
124 129 private void sendTrapError(Player player) {
@@ -134,9 +139,9 @@ private void createTrap(Player player, Material trapMaterial, int depth, boolean
134 139 Trap newTrap = new Trap(getTrapType(trapMaterial), trapMaterial, player.getName(), trapLoc, persistent);
135 140 if (newTrap.createBlocks()) {
136 141 player.sendMessage(Prefix.getMenuPrefix() + ChatColor.WHITE + "Trap ID [" + ChatColor.YELLOW
137   - + Trap.getTrapList().size() + ChatColor.WHITE + "] set with " + BlockColor.getBlockColor(trapMaterial)
  142 + + trapList.size() + ChatColor.WHITE + "] set with " + BlockColor.getBlockColor(trapMaterial)
138 143 + Format.capitalize(Format.getFormattedName(trapMaterial, 1)) + ChatColor.WHITE + getFormattedDepthString(depth));
139   - Trap.getTrapList().add(newTrap);
  144 + trapList.add(newTrap);
140 145 } else {
141 146 player.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " Unable to place a trap here");
142 147 player.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + " There's another one in the way!");
@@ -200,14 +205,14 @@ private boolean isSensibleTrapBlock(Material trap) {
200 205 }
201 206
202 207 public boolean isTrapBlock(Location loc) {
203   - return Trap.getInverseList().containsKey(loc.getBlock());
  208 + return inverseList.containsKey(loc.getBlock());
204 209 }
205 210
206 211 public void handleTrapBlockBreak(BlockBreakEvent event) {
207 212 event.setCancelled(true);
208 213 Player player = event.getPlayer();
209 214 Block block = event.getBlock();
210   - Trap trap = Trap.getInverseList().get(block);
  215 + Trap trap = inverseList.get(block);
211 216 if (fd.getPermissions().hasPerm(player, "fd.trap")) {
212 217 //player.sendMessage(ChatColor.AQUA + "Trap block removed");
213 218 sendTrapRemovedMessage(player, trap);
@@ -243,12 +248,93 @@ public void handleTrapBlockBreak(BlockBreakEvent event) {
243 248 }
244 249 }
245 250
246   - public void sendTrapRemovedMessage(CommandSender sender, Trap trap) {
  251 + public static void listTraps(CommandSender sender, int page) { // TODO: Page numbers
  252 + sender.sendMessage(Prefix.getMenuPrefix() + Format.formatMenuHeader("Active Traps"));
  253 + if (trapList.isEmpty()) {
  254 + sender.sendMessage(ChatColor.RED + " None");
  255 + return;
  256 + }
  257 + if (sender.hasPermission("fd.trap.remove.all") || sender.isOp()) {
  258 + if (page >= 0 && ( (page) *5 < trapList.size()) ) { //sane page specified?
  259 + int id1 = (page)*5 ; //begin of the substring
  260 + int id2 = (page +1) *5 -1; //end of the substring
  261 + if (id2 > trapList.size()) {
  262 + id2 = trapList.size()-1;
  263 + }
  264 + for (Trap object : trapList) {
  265 + TrapHandler.sendTrapListing(sender, object);
  266 + }
  267 + } else {
  268 + sender.sendMessage(ChatColor.RED + "Page number is invalid");
  269 + }
  270 + } else if (sender.hasPermission("fd.trap.remove.self")) { // permission to remove, and thus to see own traps
  271 + ArrayList<Trap> showList = new ArrayList<Trap>();
  272 + for (Trap trap : trapList) {
  273 + if (trap.getPlacer().equals(sender.getName())) {
  274 + showList.add(trap);
  275 + }
  276 + }
  277 + if (page >= 0 && ( (page) *5 < showList.size()) ) { //sane page specified?
  278 + int id1 = (page)*5 ; //begin of the substring
  279 + int id2 = (page +1) *5 -1; //end of the substring
  280 + if (id2 > showList.size()) {
  281 + id2 = showList.size()-1;
  282 + }
  283 + for (Trap object : showList) {
  284 + TrapHandler.sendTrapListing(sender, object);
  285 + }
  286 + } else {
  287 + sender.sendMessage(ChatColor.RED + "Page number is invalid");
  288 + }
  289 + } else {
  290 + sender.sendMessage(Prefix.getChatPrefix() + ChatColor.RED + "You don't have permission to view any traps");
  291 + }
  292 +
  293 + }
  294 +
  295 + public static void sendTrapListing(CommandSender sender, Trap trap) {
  296 + sender.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + trap.getID() + ChatColor.WHITE + "] "
  297 + + ChatColor.AQUA + DateFormat.getDateInstance(DateFormat.MEDIUM).format((trap.getTime())) + ChatColor.WHITE
  298 + + " @ x" + Format.leftGreenParen + trap.getLocation().getBlockX() + Format.rightGreenParen
  299 + + " y" + Format.leftGreenParen + trap.getLocation().getBlockY() + Format.rightGreenParen
  300 + + " z" + Format.leftGreenParen + trap.getLocation().getBlockZ() + Format.rightGreenParen + " "
  301 + + ChatColor.RED + (trap.isPersistent() ? "{Persistent}" : ChatColor.GREEN + "{Breakable}" ));
  302 + sender.sendMessage(" " + BlockColor.getBlockColor(trap.getMaterial())
  303 + + Format.capitalize(Format.getFormattedName(trap.getMaterial(), 1)) + ChatColor.WHITE
  304 + + " placed by " + ChatColor.YELLOW + trap.getPlacer() + ChatColor.WHITE + " in world "
  305 + + ChatColor.YELLOW + trap.getLocation().getWorld().getName());
  306 + }
  307 +
  308 + public void removeTrapCmd(CommandSender sender, int id) {
  309 + if (id >= 0 && id < trapList.size()) {
  310 + Trap trap = trapList.get(id);
  311 + if ((trap.getPlacer().equals(sender.getName())) &&
  312 + (sender.hasPermission("fd.trap.remove.self") || sender.hasPermission("fd.trap.remove.all"))) {
  313 + Block[] temp = trap.returnLocations(this.location.getWorld());
  314 + for (int i = 0; i < temp.length; i++) {
  315 + temp[i].setType(oldMat[i]);
  316 + inverseList.remove(temp[i]);
  317 + }
  318 + trapList.remove(this);
  319 + sendTrapRemovedMessage(sender, trapList.get(id));
  320 + }
  321 + } else {
  322 + System.out.println("FoundDiamonds: What just happened?");
  323 + //TODO then what happens?
  324 + }
  325 + }
  326 +
  327 + private void sendTrapRemovedMessage(CommandSender sender, Trap trap) {
247 328 sender.sendMessage(Prefix.getMenuPrefix() + ChatColor.WHITE + "Trap ID " + ChatColor.WHITE + "["
248   - + ChatColor.YELLOW + Trap.getTrapList().indexOf(trap) + ChatColor.WHITE + "]" + ChatColor.GREEN +" removed successfully"); }
  329 + + ChatColor.YELLOW + trapList.indexOf(trap) + ChatColor.WHITE + "]" + ChatColor.GREEN +" removed successfully");
  330 + }
249 331
250   - public ArrayList<Trap> getTrapBlocks() {
251   - return Trap.getTrapList();
252   - }
  332 + public ArrayList<Trap> getTrapList() {
  333 + return trapList;
  334 + }
  335 +
  336 + public static Map<Block, Trap> getInverseList() {
  337 + return inverseList;
  338 + }
253 339
254 340 }

0 comments on commit 7bb96de

Please sign in to comment.
Something went wrong with that request. Please try again.