Misc cleanup

Upgraded mp44
This commit is contained in:
Steven Lawson 2011-10-21 13:02:07 -04:00
parent 56a4493b36
commit 98712619f5
14 changed files with 98 additions and 57 deletions

View File

@ -1,9 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -2,7 +2,6 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,10 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -1,6 +1,5 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@ -1,6 +1,5 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@ -1,20 +1,21 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Command_mp44 extends TFM_Command public class Command_mp44 extends TFM_Command
{ {
@Override @Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin)) //if (senderIsConsole || TFM_Util.isUserSuperadmin(sender, plugin))
if (senderIsConsole || sender.isOp())
{ {
if (senderIsConsole) if (senderIsConsole)
{ {
@ -31,13 +32,18 @@ public class Command_mp44 extends TFM_Command
if (args[0].equalsIgnoreCase("draw")) if (args[0].equalsIgnoreCase("draw"))
{ {
playerdata.stopArrowShooter(); playerdata.armMP44();
int schedule_id = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new ArrowShooter(sender_p), 1L, 1L);
playerdata.startArrowShooter(schedule_id); sender.sendMessage(ChatColor.GREEN + "mp44 is ARMED! Left click with gunpowder to start firing, left click again to quit.");
sender.sendMessage(ChatColor.GREEN + "Type /mp44 sling to disable. -by Madgeek1450");
sender_p.setItemInHand(new ItemStack(Material.SULPHUR, 1));
} }
else else
{ {
playerdata.stopArrowShooter(); playerdata.disarmMP44();
sender.sendMessage(ChatColor.GREEN + "mp44 Disarmed.");
} }
} }
else else
@ -47,21 +53,4 @@ public class Command_mp44 extends TFM_Command
return true; return true;
} }
class ArrowShooter implements Runnable
{
private Player _player;
public ArrowShooter(Player player)
{
_player = player;
}
@Override
public void run()
{
Arrow shot_arrow = _player.shootArrow();
shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0));
}
}
} }

View File

@ -1,6 +1,5 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@ -6,7 +6,6 @@ import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_RadarData; import me.StevenLawson.TotalFreedomMod.TFM_RadarData;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.desmin88.mobdisguise.api.MobDisguiseAPI; import me.desmin88.mobdisguise.api.MobDisguiseAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View File

@ -1,9 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@ -5,10 +5,12 @@ import java.util.Map;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Command_tossmob extends TFM_Command public class Command_tossmob extends TFM_Command
{ {
@ -82,6 +84,8 @@ public class Command_tossmob extends TFM_Command
sender.sendMessage(ChatColor.GREEN + "MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + "."); sender.sendMessage(ChatColor.GREEN + "MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".");
sender.sendMessage(ChatColor.GREEN + "Left click while holding a stick to throw mobs!"); sender.sendMessage(ChatColor.GREEN + "Left click while holding a stick to throw mobs!");
sender.sendMessage(ChatColor.GREEN + "Type '/tossmob off' to disable. -By Madgeek1450"); sender.sendMessage(ChatColor.GREEN + "Type '/tossmob off' to disable. -By Madgeek1450");
sender_p.setItemInHand(new ItemStack(Material.STICK, 1));
} }
else else
{ {

View File

@ -23,6 +23,8 @@ public class TFM_EntityListener extends EntityListener
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
event.setYield(0.0f);
} }
@Override @Override

View File

@ -30,7 +30,7 @@ public class TFM_PlayerListener extends PlayerListener
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
{ {
if (event.getMaterial() == Material.WATER_BUCKET) if (event.getMaterial() == Material.WATER_BUCKET)
@ -66,11 +66,29 @@ public class TFM_PlayerListener extends PlayerListener
Location player_pos = player.getLocation(); Location player_pos = player.getLocation();
Vector direction = player_pos.getDirection().normalize(); Vector direction = player_pos.getDirection().normalize();
Location rez_pos = player_pos.add(direction.multiply(2.0)); Location rez_pos = player_pos.add(direction.multiply(2.0));
LivingEntity rezzed_mob = player.getWorld().spawnCreature(rez_pos, playerdata.mobThrowerCreature()); LivingEntity rezzed_mob = player.getWorld().spawnCreature(rez_pos, playerdata.mobThrowerCreature());
rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed())); rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
playerdata.enqueueMob(rezzed_mob); playerdata.enqueueMob(rezzed_mob);
event.setCancelled(true);
}
}
else if (event.getMaterial() == Material.SULPHUR)
{
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(player, plugin);
if (playerdata.isMP44Armed())
{
if (playerdata.toggleMP44Firing())
{
playerdata.startArrowShooter(plugin);
}
else
{
playerdata.stopArrowShooter();
}
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -114,7 +132,7 @@ public class TFM_PlayerListener extends PlayerListener
if (playerdata.isCaged()) if (playerdata.isCaged())
{ {
Location target_pos = p.getLocation().add(0, 1, 0); Location target_pos = p.getLocation().add(0, 1, 0);
boolean out_of_cage = false; boolean out_of_cage = false;
if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld())) if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld()))
{ {
@ -239,13 +257,13 @@ public class TFM_PlayerListener extends PlayerListener
public void onPlayerKick(PlayerKickEvent event) public void onPlayerKick(PlayerKickEvent event)
{ {
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(event.getPlayer(), plugin); TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(event.getPlayer(), plugin);
playerdata.stopArrowShooter(); playerdata.disarmMP44();
} }
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) public void onPlayerQuit(PlayerQuitEvent event)
{ {
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(event.getPlayer(), plugin); TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(event.getPlayer(), plugin);
playerdata.stopArrowShooter(); playerdata.disarmMP44();
} }
} }

View File

@ -5,12 +5,11 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.CreatureType; import org.bukkit.entity.*;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public class TFM_UserInfo public class TFM_UserInfo
{ {
private Player player;
private boolean user_frozen = false; private boolean user_frozen = false;
private int msg_count = 0; private int msg_count = 0;
private int block_destroy_total = 0; private int block_destroy_total = 0;
@ -30,9 +29,12 @@ public class TFM_UserInfo
private double mob_thrower_speed = 4.0; private double mob_thrower_speed = 4.0;
private List<LivingEntity> mob_thrower_queue = new ArrayList<LivingEntity>(); private List<LivingEntity> mob_thrower_queue = new ArrayList<LivingEntity>();
private int mp44_schedule_id = -1; private int mp44_schedule_id = -1;
private boolean mp44_armed = false;
private boolean mp44_firing = false;
public TFM_UserInfo() private TFM_UserInfo(Player player)
{ {
this.player = player;
} }
public static TFM_UserInfo getPlayerData(Player p, TotalFreedomMod tfm) public static TFM_UserInfo getPlayerData(Player p, TotalFreedomMod tfm)
@ -40,7 +42,7 @@ public class TFM_UserInfo
TFM_UserInfo playerdata = tfm.userinfo.get(p); TFM_UserInfo playerdata = tfm.userinfo.get(p);
if (playerdata == null) if (playerdata == null)
{ {
playerdata = new TFM_UserInfo(); playerdata = new TFM_UserInfo(p);
tfm.userinfo.put(p, playerdata); tfm.userinfo.put(p, playerdata);
} }
return playerdata; return playerdata;
@ -84,7 +86,7 @@ public class TFM_UserInfo
{ {
return this.user_caged; return this.user_caged;
} }
public enum CageLayer public enum CageLayer
{ {
INNER, OUTER INNER, OUTER
@ -273,9 +275,11 @@ public class TFM_UserInfo
} }
} }
public void startArrowShooter(int schedule_id) public void startArrowShooter(TotalFreedomMod plugin)
{ {
this.mp44_schedule_id = schedule_id; this.stopArrowShooter();
this.mp44_schedule_id = Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new ArrowShooter(this.player), 1L, 1L);
mp44_firing = true;
} }
public void stopArrowShooter() public void stopArrowShooter()
@ -285,5 +289,46 @@ public class TFM_UserInfo
Bukkit.getScheduler().cancelTask(this.mp44_schedule_id); Bukkit.getScheduler().cancelTask(this.mp44_schedule_id);
this.mp44_schedule_id = -1; this.mp44_schedule_id = -1;
} }
mp44_firing = false;
}
class ArrowShooter implements Runnable
{
private Player _player;
public ArrowShooter(Player player)
{
this._player = player;
}
@Override
public void run()
{
Arrow shot_arrow = _player.shootArrow();
shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0));
}
}
public void armMP44()
{
mp44_armed = true;
this.stopArrowShooter();
}
public void disarmMP44()
{
mp44_armed = false;
this.stopArrowShooter();
}
public boolean isMP44Armed()
{
return this.mp44_armed;
}
public boolean toggleMP44Firing()
{
this.mp44_firing = !this.mp44_firing;
return this.mp44_firing;
} }
} }

View File

@ -22,11 +22,7 @@ import org.bukkit.entity.*;
public class TFM_Util public class TFM_Util
{ {
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
public TFM_Util()
{
}
public static void tfm_broadcastMessage(String message, ChatColor color) public static void tfm_broadcastMessage(String message, ChatColor color)
{ {
log.info(message); log.info(message);