Fix landmine.

This commit is contained in:
StevenLawson 2014-07-19 17:34:12 -04:00
parent 73214165a5
commit 7f7312c0a2
2 changed files with 46 additions and 29 deletions

View File

@ -1,6 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry; import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -22,48 +23,66 @@ public class Command_landmine extends TFM_Command
if (!TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean()) if (!TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean())
{ {
playerMsg("The landmine is currently disabled.", ChatColor.GREEN); 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); 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 ("list".equalsIgnoreCase(args[0]))
if (args.length >= 1)
{ {
try final Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
{ while (landmines.hasNext())
radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0])));
}
catch (NumberFormatException ex)
{ {
playerMsg(landmines.next().toString());
} }
return true;
} }
Block landmine = sender_p.getLocation().getBlock().getRelative(BlockFace.DOWN); try
landmine.setType(Material.TNT); {
TFM_LandmineData.landmines.add(new TFM_LandmineData(landmine.getLocation(), sender_p, radius)); radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0])));
}
playerMsg("Landmine planted. Radius: " + radius + " blocks.", ChatColor.GREEN); 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; return true;
} }
public static class TFM_LandmineData public static class TFM_LandmineData
{ {
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>(); public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
public Location location;
public Player player;
public double radius;
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 = location;
this.location = landmine_pos;
this.player = player; this.player = player;
this.radius = radius; this.radius = radius;
} }
@Override
public String toString()
{
return this.location.toString() + ", " + this.radius + ", " + this.player.getName();
}
} }
} }

View File

@ -488,13 +488,12 @@ public class TFM_PlayerListener implements Listener
return; return;
} }
//TODO: Fix landmines final Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator();
Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator();
while (landmines.hasNext()) 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) if (location.getBlock().getType() != Material.TNT)
{ {
landmines.remove(); landmines.remove();
@ -508,7 +507,7 @@ public class TFM_PlayerListener implements Listener
if (!player.getWorld().equals(location.getWorld())) if (!player.getWorld().equals(location.getWorld()))
{ {
break; continue;
} }
if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius))) 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); 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.setFuseTicks(40);
tnt1.setPassenger(player); tnt1.setPassenger(player);
tnt1.setVelocity(new Vector(0.0, 2.0, 0.0)); 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); tnt2.setFuseTicks(1);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
landmines.remove(); landmines.remove();
} }
} }
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)