diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java index dd7f10b..076c8b9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_landmine.java @@ -1,6 +1,7 @@ package me.StevenLawson.TotalFreedomMod.Commands; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; import org.bukkit.ChatColor; @@ -22,48 +23,66 @@ public class Command_landmine extends TFM_Command if (!TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean()) { playerMsg("The landmine is currently disabled.", ChatColor.GREEN); + return true; } - else if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) + + if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) { playerMsg("Explosions are currently disabled.", ChatColor.GREEN); + return true; } - else if (sender.isOp()) + + double radius = 2.0; + + if (args.length >= 1) { - double radius = 2.0; - if (args.length >= 1) + if ("list".equalsIgnoreCase(args[0])) { - try - { - radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0]))); - } - catch (NumberFormatException ex) + final Iterator landmines = TFM_LandmineData.landmines.iterator(); + while (landmines.hasNext()) { + playerMsg(landmines.next().toString()); } + return true; } - Block landmine = sender_p.getLocation().getBlock().getRelative(BlockFace.DOWN); - landmine.setType(Material.TNT); - TFM_LandmineData.landmines.add(new TFM_LandmineData(landmine.getLocation(), sender_p, radius)); - - playerMsg("Landmine planted. Radius: " + radius + " blocks.", ChatColor.GREEN); + try + { + radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0]))); + } + catch (NumberFormatException ex) + { + } } + final Block landmine = sender_p.getLocation().getBlock().getRelative(BlockFace.DOWN); + landmine.setType(Material.TNT); + TFM_LandmineData.landmines.add(new TFM_LandmineData(landmine.getLocation(), sender_p, radius)); + + playerMsg("Landmine planted - Radius = " + radius + " blocks.", ChatColor.GREEN); + return true; } public static class TFM_LandmineData { - public static List landmines = new ArrayList(); - public Location location; - public Player player; - public double radius; + public static final List landmines = new ArrayList(); - public TFM_LandmineData(Location landmine_pos, Player player, double radius) + public final Location location; + public final Player player; + public final double radius; + + public TFM_LandmineData(Location location, Player player, double radius) { - super(); - this.location = landmine_pos; + this.location = location; this.player = player; this.radius = radius; } + + @Override + public String toString() + { + return this.location.toString() + ", " + this.radius + ", " + this.player.getName(); + } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 588e95b..484531a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -488,13 +488,12 @@ public class TFM_PlayerListener implements Listener return; } - //TODO: Fix landmines - Iterator landmines = Command_landmine.TFM_LandmineData.landmines.iterator(); + final Iterator landmines = Command_landmine.TFM_LandmineData.landmines.iterator(); while (landmines.hasNext()) { - Command_landmine.TFM_LandmineData landmine = landmines.next(); + final Command_landmine.TFM_LandmineData landmine = landmines.next(); - Location location = landmine.location; + final Location location = landmine.location; if (location.getBlock().getType() != Material.TNT) { landmines.remove(); @@ -508,7 +507,7 @@ public class TFM_PlayerListener implements Listener if (!player.getWorld().equals(location.getWorld())) { - break; + continue; } if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius))) @@ -518,18 +517,17 @@ public class TFM_PlayerListener implements Listener landmine.location.getBlock().setType(Material.AIR); - TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class); + final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class); tnt1.setFuseTicks(40); tnt1.setPassenger(player); tnt1.setVelocity(new Vector(0.0, 2.0, 0.0)); - TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class); + final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class); tnt2.setFuseTicks(1); player.setGameMode(GameMode.SURVIVAL); landmines.remove(); } - } @EventHandler(priority = EventPriority.NORMAL)