From 45cc2e8c47e1fbde049bc9f015d33fda6fdf3a5b Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Wed, 19 Oct 2011 12:04:44 -0400 Subject: [PATCH] Misc --- .../Commands/Command_expel.java | 13 +++----- .../Commands/Command_radar.java | 31 ++++++++++--------- .../Listener/TFM_PlayerListener.java | 14 ++++++++- .../TotalFreedomMod/TFM_RadarData.java | 8 ++--- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java index ae7aee2..b10a274 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_expel.java @@ -48,19 +48,16 @@ public class Command_expel extends TFM_Command } Location sender_pos = sender_p.getLocation(); - for (Player p : Bukkit.getOnlinePlayers()) + for (Player p : sender_pos.getWorld().getPlayers()) { if (!p.equals(sender_p)) { Location target_pos = p.getLocation(); - if (target_pos.getWorld().equals(sender_pos.getWorld())) + if (target_pos.distance(sender_pos) < radius) { - if (target_pos.distance(sender_pos) < radius) - { - sender.sendMessage("Pushing " + p.getName()); - Vector expel_direction = target_pos.subtract(sender_pos).toVector().normalize(); - p.setVelocity(expel_direction.multiply(strength)); - } + sender.sendMessage("Pushing " + p.getName()); + Vector expel_direction = target_pos.subtract(sender_pos).toVector().normalize(); + p.setVelocity(expel_direction.multiply(strength)); } } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java index c67b552..e0e11b2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_radar.java @@ -23,24 +23,28 @@ public class Command_radar extends TFM_Command sender.sendMessage(TotalFreedomMod.NOT_FROM_CONSOLE); return true; } - - Player sender_player = Bukkit.getPlayerExact(sender.getName()); - Location sender_pos = sender_player.getLocation(); - String sender_world = sender_player.getWorld().getName(); + + Location sender_pos = sender_p.getLocation(); List radar_data = new ArrayList(); - for (Player p : Bukkit.getOnlinePlayers()) + for (Player p : sender_pos.getWorld().getPlayers()) { - if (sender_world.equals(p.getWorld().getName()) && !p.getName().equals(sender.getName())) + if (!p.equals(sender_p)) { radar_data.add(new TFM_RadarData(p, sender_pos.distance(p.getLocation()), p.getLocation())); } } + + if (radar_data.isEmpty()) + { + sender.sendMessage(ChatColor.YELLOW + "You are the only player in this world. (Forever alone...)"); + return true; + } Collections.sort(radar_data, new TFM_RadarData()); - sender.sendMessage(ChatColor.YELLOW + "People nearby in " + sender_world + ":"); + sender.sendMessage(ChatColor.YELLOW + "People nearby in " + sender_pos.getWorld().getName() + ":"); int countmax = 5; if (args.length == 1) @@ -53,19 +57,18 @@ public class Command_radar extends TFM_Command { } } - - int count = 0; + for (TFM_RadarData i : radar_data) { - if (count++ > countmax) - { - break; - } - sender.sendMessage(ChatColor.YELLOW + String.format("%s - %d, Disguised: %s", i.player.getName(), Math.round(i.distance), MobDisguiseAPI.isDisguised(i.player) ? "Yes" : "No")); + + if (--countmax <= 0) + { + break; + } } return true; diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 7c51012..27119eb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -5,6 +5,7 @@ import java.util.regex.Pattern; import me.StevenLawson.TotalFreedomMod.TFM_UserInfo; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -113,8 +114,18 @@ public class TFM_PlayerListener extends PlayerListener if (playerdata.isCaged()) { Location target_pos = p.getLocation().add(0, 1, 0); + + boolean out_of_cage = false; + if (!target_pos.getWorld().equals(playerdata.getCagePos().getWorld())) + { + out_of_cage = true; + } + else + { + out_of_cage = target_pos.distance(playerdata.getCagePos()) > 2.5; + } - if (target_pos.distance(playerdata.getCagePos()) > 2.5) + if (out_of_cage) { playerdata.setCaged(true, target_pos, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER), playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); playerdata.regenerateHistory(); @@ -146,6 +157,7 @@ public class TFM_PlayerListener extends PlayerListener { p.setOp(false); p.kickPlayer("No Spamming"); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("tempban %s 1m", p.getName())); TFM_Util.tfm_broadcastMessage(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); playerdata.resetMsgCount(); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java b/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java index b544f89..a07d24c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_RadarData.java @@ -10,11 +10,11 @@ public class TFM_RadarData implements Comparator public double distance; public Location location; - public TFM_RadarData(Player inplayer, double indistance, Location inlocation) + public TFM_RadarData(Player player, double distance, Location location) { - this.player = inplayer; - this.distance = indistance; - this.location = inlocation; + this.player = player; + this.distance = distance; + this.location = location; } public TFM_RadarData()