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;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
import org.bukkit.ChatColor;
@ -22,16 +23,29 @@ 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)
{
if ("list".equalsIgnoreCase(args[0]))
{
final Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
while (landmines.hasNext())
{
playerMsg(landmines.next().toString());
}
return true;
}
try
{
radius = Math.max(2.0, Math.min(6.0, Double.parseDouble(args[0])));
@ -41,29 +55,34 @@ public class Command_landmine extends TFM_Command
}
}
Block landmine = sender_p.getLocation().getBlock().getRelative(BlockFace.DOWN);
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);
}
playerMsg("Landmine planted - Radius = " + radius + " blocks.", ChatColor.GREEN);
return true;
}
public static class TFM_LandmineData
{
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
public Location location;
public Player player;
public double radius;
public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
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();
}
}
}

View File

@ -488,13 +488,12 @@ public class TFM_PlayerListener implements Listener
return;
}
//TODO: Fix landmines
Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator();
final Iterator<Command_landmine.TFM_LandmineData> 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)