Converted variable names to CamelCase as convention

This commit is contained in:
JeromSar 2013-08-25 18:32:01 +02:00
parent 55d94b5d59
commit 5981f7f33f
11 changed files with 454 additions and 455 deletions

View File

@ -35,27 +35,27 @@ public class TFM_BlockListener implements Listener
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location block_pos = event.getBlock().getLocation(); Location blockLocation = event.getBlock().getLocation();
if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean()) if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
{ {
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
Location player_pos = player.getLocation(); Location playerLocation = player.getLocation();
final double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue(); final double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue();
boolean out_of_range = false; boolean outOfRange = false;
if (!player_pos.getWorld().equals(block_pos.getWorld())) if (!playerLocation.getWorld().equals(blockLocation.getWorld()))
{ {
out_of_range = true; outOfRange = true;
} }
else if (player_pos.distanceSquared(block_pos) > (nukeMonitorRange * nukeMonitorRange)) else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nukeMonitorRange))
{ {
out_of_range = true; outOfRange = true;
} }
if (out_of_range) if (outOfRange)
{ {
if (playerdata.incrementAndGetFreecamDestroyCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger()) if (playerdata.incrementAndGetFreecamDestroyCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
{ {
@ -93,7 +93,7 @@ public class TFM_BlockListener implements Listener
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isUserSuperadmin(player))
{ {
if (TFM_ProtectedArea.isInProtectedArea(block_pos)) if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -111,27 +111,27 @@ public class TFM_BlockListener implements Listener
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location block_pos = event.getBlock().getLocation(); Location blockLocation = event.getBlock().getLocation();
if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean()) if (TFM_ConfigEntry.NUKE_MONITOR.getBoolean())
{ {
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
Location player_pos = player.getLocation(); Location playerLocation = player.getLocation();
double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue(); double nukeMonitorRange = TFM_ConfigEntry.NUKE_MONITOR_RANGE.getDouble().doubleValue();
boolean out_of_range = false; boolean outOfRange = false;
if (!player_pos.getWorld().equals(block_pos.getWorld())) if (!playerLocation.getWorld().equals(blockLocation.getWorld()))
{ {
out_of_range = true; outOfRange = true;
} }
else if (player_pos.distanceSquared(block_pos) > (nukeMonitorRange * nukeMonitorRange)) else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nukeMonitorRange))
{ {
out_of_range = true; outOfRange = true;
} }
if (out_of_range) if (outOfRange)
{ {
if (playerdata.incrementAndGetFreecamPlaceCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger()) if (playerdata.incrementAndGetFreecamPlaceCount() > TFM_ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger())
{ {
@ -169,7 +169,7 @@ public class TFM_BlockListener implements Listener
{ {
if (!TFM_SuperadminList.isUserSuperadmin(player)) if (!TFM_SuperadminList.isUserSuperadmin(player))
{ {
if (TFM_ProtectedArea.isInProtectedArea(block_pos)) if (TFM_ProtectedArea.isInProtectedArea(blockLocation))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

@ -348,7 +348,7 @@ public class TFM_PlayerListener implements Listener
{ {
TFM_LandmineData landmine = landmines.next(); TFM_LandmineData landmine = landmines.next();
Location landmine_pos = landmine.landmine_pos; Location landmine_pos = landmine.location;
if (landmine_pos.getBlock().getType() != Material.TNT) if (landmine_pos.getBlock().getType() != Material.TNT)
{ {
landmines.remove(); landmines.remove();
@ -361,7 +361,7 @@ public class TFM_PlayerListener implements Listener
{ {
if (player.getLocation().distanceSquared(landmine_pos) <= (landmine.radius * landmine.radius)) if (player.getLocation().distanceSquared(landmine_pos) <= (landmine.radius * landmine.radius))
{ {
landmine.landmine_pos.getBlock().setType(Material.AIR); landmine.location.getBlock().setType(Material.AIR);
TNTPrimed tnt1 = landmine_pos.getWorld().spawn(landmine_pos, TNTPrimed.class); TNTPrimed tnt1 = landmine_pos.getWorld().spawn(landmine_pos, TNTPrimed.class);
tnt1.setFuseTicks(40); tnt1.setFuseTicks(40);

View File

@ -8,13 +8,13 @@ import org.bukkit.entity.Player;
public class TFM_LandmineData public class TFM_LandmineData
{ {
public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>(); public static List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
public Location landmine_pos; public Location location;
public Player player; public Player player;
public double radius; public double radius;
public TFM_LandmineData(Location landmine_pos, Player player, double radius) public TFM_LandmineData(Location landmine_pos, Player player, double radius)
{ {
this.landmine_pos = landmine_pos; this.location = landmine_pos;
this.player = player; this.player = player;
this.radius = radius; this.radius = radius;
} }

View File

@ -22,44 +22,44 @@ public class TFM_PlayerData
{ {
public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>(); public final static Map<Player, TFM_PlayerData> userinfo = new HashMap<Player, TFM_PlayerData>();
private final Player player; private final Player player;
private final String ip_address; private final String ip;
private final String player_name; private final String username;
private boolean user_frozen = false; private boolean isFrozen = false;
private boolean is_muted = false; private boolean isMuted = false;
private boolean is_halted = false; private boolean isHalted = false;
private int msg_count = 0; private int messageCount = 0;
private int block_destroy_total = 0; private int totalBlockDestroy = 0;
private int block_place_total = 0; private int totalBlockPlace = 0;
private int freecam_destroy_count = 0; private int freecamDestroyCount = 0;
private int freecam_place_count = 0; private int freecamPlaceCount = 0;
private boolean user_caged = false; private boolean isCaged = false;
private Location user_cage_pos; private Location cagePosition;
private List<TFM_BlockData> user_cage_history = new ArrayList<TFM_BlockData>(); private List<TFM_BlockData> cageHistory = new ArrayList<TFM_BlockData>();
private Material cage_material_outer = Material.GLASS; private Material cageOuterMaterial = Material.GLASS;
private Material cage_material_inner = Material.AIR; private Material cageInnerMatterial = Material.AIR;
private boolean is_orbiting = false; private boolean isOrbiting = false;
private double orbit_strength = 10.0; private double orbitStrength = 10.0;
private boolean mob_thrower_enabled = false; private boolean mobThrowerEnabled = false;
private EntityType mob_thrower_creature = EntityType.PIG; private EntityType mobThrowerEntity = EntityType.PIG;
private double mob_thrower_speed = 4.0; private double mobThrowerSpeed = 4.0;
private List<LivingEntity> mob_thrower_queue = new ArrayList<LivingEntity>(); private List<LivingEntity> mobThrowerQueue = new ArrayList<LivingEntity>();
private BukkitTask mp44_schedule_id = null; private BukkitTask mp44ScheduleId = null;
private boolean mp44_armed = false; private boolean mp44Armed = false;
private boolean mp44_firing = false; private boolean mp44Firing = false;
private BukkitTask lockup_schedule_id = null; private BukkitTask lockupScheduleId = null;
private String last_message = ""; private String lastMessage = "";
private boolean in_adminchat = false; private boolean inAdminchat = false;
private boolean all_commands_blocked = false; private boolean allCommandsBlocked = false;
private Boolean superadmin_id_verified = null; private Boolean verifiedSuperadminId = null;
private String last_command = ""; private String lastCommand = "";
private boolean cmdspy_enabled = false; private boolean cmdspyEnabled = false;
private String tag = null; private String tag = null;
public TFM_PlayerData(Player player) public TFM_PlayerData(Player player)
{ {
this.player = player; this.player = player;
this.ip_address = player.getAddress().getAddress().getHostAddress(); this.ip = player.getAddress().getAddress().getHostAddress();
this.player_name = player.getName(); this.username = player.getName();
} }
public static TFM_PlayerData getPlayerData(Player player) public static TFM_PlayerData getPlayerData(Player player)
@ -72,20 +72,20 @@ public class TFM_PlayerData
while (it.hasNext()) while (it.hasNext())
{ {
Entry<Player, TFM_PlayerData> pair = it.next(); Entry<Player, TFM_PlayerData> pair = it.next();
TFM_PlayerData playerdata_test = pair.getValue(); TFM_PlayerData playerdataTest = pair.getValue();
if (playerdata_test.player_name.equalsIgnoreCase(player.getName())) if (playerdataTest.username.equalsIgnoreCase(player.getName()))
{ {
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode())
{ {
playerdata = playerdata_test; playerdata = playerdataTest;
break; break;
} }
else else
{ {
if (playerdata_test.ip_address.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress())) if (playerdataTest.ip.equalsIgnoreCase(player.getAddress().getAddress().getHostAddress()))
{ {
playerdata = playerdata_test; playerdata = playerdataTest;
break; break;
} }
} }
@ -104,51 +104,51 @@ public class TFM_PlayerData
public String getIpAddress() public String getIpAddress()
{ {
return ip_address; return this.ip;
} }
public String getPlayerName() public String getPlayerName()
{ {
return player_name; return this.username;
} }
public boolean isOrbiting() public boolean isOrbiting()
{ {
return is_orbiting; return this.isOrbiting;
} }
public void startOrbiting(double orbit_strength) public void startOrbiting(double strength)
{ {
this.is_orbiting = true; this.isOrbiting = true;
this.orbit_strength = orbit_strength; this.orbitStrength = strength;
} }
public void stopOrbiting() public void stopOrbiting()
{ {
is_orbiting = false; this.isOrbiting = false;
} }
public double orbitStrength() public double orbitStrength()
{ {
return orbit_strength; return this.orbitStrength;
} }
public void setCaged(boolean state) public void setCaged(boolean state)
{ {
this.user_caged = state; this.isCaged = state;
} }
public void setCaged(boolean state, Location location, Material material_outer, Material material_inner) public void setCaged(boolean state, Location location, Material outer, Material inner)
{ {
this.user_caged = state; this.isCaged = state;
this.user_cage_pos = location; this.cagePosition = location;
this.cage_material_outer = material_outer; this.cageOuterMaterial = outer;
this.cage_material_inner = material_inner; this.cageInnerMatterial = inner;
} }
public boolean isCaged() public boolean isCaged()
{ {
return user_caged; return this.isCaged;
} }
public enum CageLayer public enum CageLayer
@ -161,32 +161,32 @@ public class TFM_PlayerData
switch (layer) switch (layer)
{ {
case OUTER: case OUTER:
return this.cage_material_outer; return this.cageOuterMaterial;
case INNER: case INNER:
return this.cage_material_inner; return this.cageInnerMatterial;
default: default:
return this.cage_material_outer; return this.cageOuterMaterial;
} }
} }
public Location getCagePos() public Location getCagePos()
{ {
return user_cage_pos; return this.cagePosition;
} }
public void clearHistory() public void clearHistory()
{ {
this.user_cage_history.clear(); this.cageHistory.clear();
} }
public void insertHistoryBlock(Location location, Material material) public void insertHistoryBlock(Location location, Material material)
{ {
this.user_cage_history.add(new TFM_BlockData(location, material)); this.cageHistory.add(new TFM_BlockData(location, material));
} }
public void regenerateHistory() public void regenerateHistory()
{ {
for (TFM_BlockData blockdata : this.user_cage_history) for (TFM_BlockData blockdata : this.cageHistory)
{ {
blockdata.location.getBlock().setType(blockdata.material); blockdata.location.getBlock().setType(blockdata.material);
} }
@ -206,97 +206,97 @@ public class TFM_PlayerData
public boolean isFrozen() public boolean isFrozen()
{ {
return this.user_frozen; return this.isFrozen;
} }
public void setFrozen(boolean fr) public void setFrozen(boolean fr)
{ {
this.user_frozen = fr; this.isFrozen = fr;
} }
public void resetMsgCount() public void resetMsgCount()
{ {
this.msg_count = 0; this.messageCount = 0;
} }
public int incrementAndGetMsgCount() public int incrementAndGetMsgCount()
{ {
return this.msg_count++; return this.messageCount++;
} }
public int incrementAndGetBlockDestroyCount() public int incrementAndGetBlockDestroyCount()
{ {
return this.block_destroy_total++; return this.totalBlockDestroy++;
} }
public void resetBlockDestroyCount() public void resetBlockDestroyCount()
{ {
this.block_destroy_total = 0; this.totalBlockDestroy = 0;
} }
public int incrementAndGetBlockPlaceCount() public int incrementAndGetBlockPlaceCount()
{ {
return this.block_place_total++; return this.totalBlockPlace++;
} }
public void resetBlockPlaceCount() public void resetBlockPlaceCount()
{ {
this.block_place_total = 0; this.totalBlockPlace = 0;
} }
public int incrementAndGetFreecamDestroyCount() public int incrementAndGetFreecamDestroyCount()
{ {
return this.freecam_destroy_count++; return this.freecamDestroyCount++;
} }
public void resetFreecamDestroyCount() public void resetFreecamDestroyCount()
{ {
this.freecam_destroy_count = 0; this.freecamDestroyCount = 0;
} }
public int incrementAndGetFreecamPlaceCount() public int incrementAndGetFreecamPlaceCount()
{ {
return this.freecam_place_count++; return this.freecamPlaceCount++;
} }
public void resetFreecamPlaceCount() public void resetFreecamPlaceCount()
{ {
this.freecam_place_count = 0; this.freecamPlaceCount = 0;
} }
public void enableMobThrower(EntityType mob_thrower_creature, double mob_thrower_speed) public void enableMobThrower(EntityType mobThrowerCreature, double mobThrowerSpeed)
{ {
this.mob_thrower_enabled = true; this.mobThrowerEnabled = true;
this.mob_thrower_creature = mob_thrower_creature; this.mobThrowerEntity = mobThrowerCreature;
this.mob_thrower_speed = mob_thrower_speed; this.mobThrowerSpeed = mobThrowerSpeed;
} }
public void disableMobThrower() public void disableMobThrower()
{ {
this.mob_thrower_enabled = false; this.mobThrowerEnabled = false;
} }
public EntityType mobThrowerCreature() public EntityType mobThrowerCreature()
{ {
return mob_thrower_creature; return this.mobThrowerEntity;
} }
public double mobThrowerSpeed() public double mobThrowerSpeed()
{ {
return mob_thrower_speed; return this.mobThrowerSpeed;
} }
public boolean mobThrowerEnabled() public boolean mobThrowerEnabled()
{ {
return mob_thrower_enabled; return this.mobThrowerEnabled;
} }
public void enqueueMob(LivingEntity mob) public void enqueueMob(LivingEntity mob)
{ {
mob_thrower_queue.add(mob); mobThrowerQueue.add(mob);
if (mob_thrower_queue.size() > 4) if (mobThrowerQueue.size() > 4)
{ {
LivingEntity oldmob = mob_thrower_queue.remove(0); LivingEntity oldmob = mobThrowerQueue.remove(0);
if (oldmob != null) if (oldmob != null)
{ {
oldmob.damage(500.0); oldmob.damage(500.0);
@ -307,85 +307,85 @@ public class TFM_PlayerData
public void startArrowShooter(TotalFreedomMod plugin) public void startArrowShooter(TotalFreedomMod plugin)
{ {
this.stopArrowShooter(); this.stopArrowShooter();
this.mp44_schedule_id = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L); this.mp44ScheduleId = new ArrowShooter(this.player).runTaskTimer(plugin, 1L, 1L);
mp44_firing = true; this.mp44Firing = true;
} }
public void stopArrowShooter() public void stopArrowShooter()
{ {
if (this.mp44_schedule_id != null) if (this.mp44ScheduleId != null)
{ {
this.mp44_schedule_id.cancel(); this.mp44ScheduleId.cancel();
this.mp44_schedule_id = null; this.mp44ScheduleId = null;
} }
mp44_firing = false; this.mp44Firing = false;
} }
private class ArrowShooter extends BukkitRunnable private class ArrowShooter extends BukkitRunnable
{ {
private Player _player; private Player player;
public ArrowShooter(Player player) public ArrowShooter(Player player)
{ {
this._player = player; this.player = player;
} }
@Override @Override
public void run() public void run()
{ {
Arrow shot_arrow = _player.launchProjectile(Arrow.class); Arrow shot = player.launchProjectile(Arrow.class);
shot_arrow.setVelocity(shot_arrow.getVelocity().multiply(2.0)); shot.setVelocity(shot.getVelocity().multiply(2.0));
} }
} }
public void armMP44() public void armMP44()
{ {
mp44_armed = true; this.mp44Armed = true;
this.stopArrowShooter(); this.stopArrowShooter();
} }
public void disarmMP44() public void disarmMP44()
{ {
mp44_armed = false; this.mp44Armed = false;
this.stopArrowShooter(); this.stopArrowShooter();
} }
public boolean isMP44Armed() public boolean isMP44Armed()
{ {
return mp44_armed; return this.mp44Armed;
} }
public boolean toggleMP44Firing() public boolean toggleMP44Firing()
{ {
this.mp44_firing = !this.mp44_firing; this.mp44Firing = !this.mp44Firing;
return mp44_firing; return mp44Firing;
} }
public boolean isMuted() public boolean isMuted()
{ {
return is_muted; return isMuted;
} }
public void setMuted(boolean is_muted) public void setMuted(boolean muted)
{ {
this.is_muted = is_muted; this.isMuted = muted;
} }
public boolean isHalted() public boolean isHalted()
{ {
return is_halted; return this.isHalted;
} }
public void setHalted(boolean is_halted) public void setHalted(boolean halted)
{ {
this.is_halted = is_halted; this.isHalted = halted;
if (is_halted) if (halted)
{ {
player.setOp(false); player.setOp(false);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false); player.setFlying(false);
player.setDisplayName(player_name); player.setDisplayName(username);
player.closeInventory(); player.closeInventory();
player.setTotalExperience(0); player.setTotalExperience(0);
@ -409,76 +409,76 @@ public class TFM_PlayerData
public BukkitTask getLockupScheduleID() public BukkitTask getLockupScheduleID()
{ {
return lockup_schedule_id; return this.lockupScheduleId;
} }
public void setLockupScheduleID(BukkitTask lockup_schedule_id) public void setLockupScheduleID(BukkitTask id)
{ {
this.lockup_schedule_id = lockup_schedule_id; this.lockupScheduleId = id;
} }
public void setLastMessage(String last_message) public void setLastMessage(String message)
{ {
this.last_message = last_message; this.lastMessage = message;
} }
public String getLastMessage() public String getLastMessage()
{ {
return last_message; return lastMessage;
} }
public void setAdminChat(boolean in_adminchat) public void setAdminChat(boolean inAdminchat)
{ {
this.in_adminchat = in_adminchat; this.inAdminchat = inAdminchat;
} }
public boolean inAdminChat() public boolean inAdminChat()
{ {
return in_adminchat; return this.inAdminchat;
} }
public boolean allCommandsBlocked() public boolean allCommandsBlocked()
{ {
return all_commands_blocked; return this.allCommandsBlocked;
} }
public void setCommandsBlocked(boolean commands_blocked) public void setCommandsBlocked(boolean commandsBlocked)
{ {
this.all_commands_blocked = commands_blocked; this.allCommandsBlocked = commandsBlocked;
} }
//If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP. // If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
//After the check for this is done in TFM_PlayerListener, never change it elsewhere. // After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public Boolean isSuperadminIdVerified() public Boolean isSuperadminIdVerified()
{ {
return superadmin_id_verified; return this.verifiedSuperadminId;
} }
//If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP. // If someone logs in to telnet or minecraft, and they are an admin, make sure that they are using a username that is associated with their IP.
//After the check for this is done in TFM_PlayerListener, never change it elsewhere. // After the check for this is done in TFM_PlayerListener, never change it elsewhere.
public void setSuperadminIdVerified(Boolean superadmin_id_verified) public void setSuperadminIdVerified(Boolean verifiedSuperadminId)
{ {
this.superadmin_id_verified = superadmin_id_verified; this.verifiedSuperadminId = verifiedSuperadminId;
} }
public String getLastCommand() public String getLastCommand()
{ {
return last_command; return lastCommand;
} }
public void setLastCommand(String last_command) public void setLastCommand(String lastCommand)
{ {
this.last_command = last_command; this.lastCommand = lastCommand;
} }
public void setCommandSpy(boolean cmdspy_enabled) public void setCommandSpy(boolean enabled)
{ {
this.cmdspy_enabled = cmdspy_enabled; this.cmdspyEnabled = enabled;
} }
public boolean cmdspyEnabled() public boolean cmdspyEnabled()
{ {
return cmdspy_enabled; return cmdspyEnabled;
} }
public void setTag(String tag) public void setTag(String tag)

View File

@ -18,27 +18,27 @@ public class TFM_ProtectedArea implements Serializable
private static final long serialVersionUID = -3270338811000937254L; private static final long serialVersionUID = -3270338811000937254L;
public static final double MAX_RADIUS = 50.0D; public static final double MAX_RADIUS = 50.0D;
private static Map<String, TFM_ProtectedArea> protectedAreas = new HashMap<String, TFM_ProtectedArea>(); private static Map<String, TFM_ProtectedArea> protectedAreas = new HashMap<String, TFM_ProtectedArea>();
private final SerializableLocation center_location; private final SerializableLocation center;
private final double radius; private final double radius;
private TFM_ProtectedArea(Location root_location, double radius) private TFM_ProtectedArea(Location root_location, double radius)
{ {
this.center_location = new SerializableLocation(root_location); this.center = new SerializableLocation(root_location);
this.radius = radius; this.radius = radius;
} }
public static boolean isInProtectedArea(Location check_location) public static boolean isInProtectedArea(Location location)
{ {
for (Map.Entry<String, TFM_ProtectedArea> protected_area : TFM_ProtectedArea.protectedAreas.entrySet()) for (Map.Entry<String, TFM_ProtectedArea> protectedArea : TFM_ProtectedArea.protectedAreas.entrySet())
{ {
Location protected_area_center = SerializableLocation.returnLocation(protected_area.getValue().center_location); Location protectedAreaCenter = SerializableLocation.returnLocation(protectedArea.getValue().center);
if (protected_area_center != null) if (protectedAreaCenter != null)
{ {
if (check_location.getWorld() == protected_area_center.getWorld()) if (location.getWorld() == protectedAreaCenter.getWorld())
{ {
double protected_area_radius = protected_area.getValue().radius; double protectedAreaRadius = protectedArea.getValue().radius;
if (check_location.distanceSquared(protected_area_center) <= (protected_area_radius * protected_area_radius)) if (location.distanceSquared(protectedAreaCenter) <= (protectedAreaRadius * protectedAreaRadius))
{ {
return true; return true;
} }
@ -49,9 +49,9 @@ public class TFM_ProtectedArea implements Serializable
return false; return false;
} }
public static void addProtectedArea(String label, Location root_location, double radius) public static void addProtectedArea(String label, Location location, double radius)
{ {
TFM_ProtectedArea.protectedAreas.put(label.toLowerCase(), new TFM_ProtectedArea(root_location, radius)); TFM_ProtectedArea.protectedAreas.put(label.toLowerCase(), new TFM_ProtectedArea(location, radius));
saveProtectedAreas(); saveProtectedAreas();
} }
@ -89,15 +89,14 @@ public class TFM_ProtectedArea implements Serializable
} }
} }
@SuppressWarnings("unchecked")
public static void loadProtectedAreas() public static void loadProtectedAreas()
{ {
try try
{ {
File input_file = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE); File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
if (input_file.exists()) if (input.exists())
{ {
FileInputStream fis = new FileInputStream(input_file); FileInputStream fis = new FileInputStream(input);
ObjectInputStream ois = new ObjectInputStream(fis); ObjectInputStream ois = new ObjectInputStream(fis);
TFM_ProtectedArea.protectedAreas = (HashMap<String, TFM_ProtectedArea>) ois.readObject(); TFM_ProtectedArea.protectedAreas = (HashMap<String, TFM_ProtectedArea>) ois.readObject();
ois.close(); ois.close();
@ -106,8 +105,8 @@ public class TFM_ProtectedArea implements Serializable
} }
catch (Exception ex) catch (Exception ex)
{ {
File input_file = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE); File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.PROTECTED_AREA_FILE);
input_file.delete(); input.delete();
TFM_Log.severe(ex); TFM_Log.severe(ex);
} }

View File

@ -18,7 +18,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
public class TFM_ServerInterface public class TFM_ServerInterface
{ {
private static final SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z"); private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
public static void setOnlineMode(boolean mode) public static void setOnlineMode(boolean mode)
{ {
@ -48,7 +48,7 @@ public class TFM_ServerInterface
nameBans.remove(name); nameBans.remove(name);
} }
public static void banUsername(String name, String reason, String source, Date expire_date) public static void banUsername(String name, String reason, String source, Date expireDate)
{ {
name = name.toLowerCase().trim(); name = name.toLowerCase().trim();
@ -67,21 +67,21 @@ public class TFM_ServerInterface
} }
} }
BanEntry ban_entry = new BanEntry(name); BanEntry entry = new BanEntry(name);
if (expire_date != null) if (expireDate != null)
{ {
ban_entry.setExpires(expire_date); entry.setExpires(expireDate);
} }
if (reason != null) if (reason != null)
{ {
ban_entry.setReason(reason); entry.setReason(reason);
} }
if (source != null) if (source != null)
{ {
ban_entry.setSource(source); entry.setSource(source);
} }
BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans(); BanList nameBans = MinecraftServer.getServer().getPlayerList().getNameBans();
nameBans.add(ban_entry); nameBans.add(entry);
} }
public static boolean isNameBanned(String name) public static boolean isNameBanned(String name)
@ -92,24 +92,24 @@ public class TFM_ServerInterface
return nameBans.getEntries().containsKey(name); return nameBans.getEntries().containsKey(name);
} }
public static void banIP(String ip, String reason, String source, Date expire_date) public static void banIP(String ip, String reason, String source, Date expireDate)
{ {
ip = ip.toLowerCase().trim(); ip = ip.toLowerCase().trim();
BanEntry ban_entry = new BanEntry(ip); BanEntry entry = new BanEntry(ip);
if (expire_date != null) if (expireDate != null)
{ {
ban_entry.setExpires(expire_date); entry.setExpires(expireDate);
} }
if (reason != null) if (reason != null)
{ {
ban_entry.setReason(reason); entry.setReason(reason);
} }
if (source != null) if (source != null)
{ {
ban_entry.setSource(source); entry.setSource(source);
} }
BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans(); BanList ipBans = MinecraftServer.getServer().getPlayerList().getIPBans();
ipBans.add(ban_entry); ipBans.add(entry);
} }
public static void unbanIP(String ip) public static void unbanIP(String ip)
@ -142,114 +142,114 @@ public class TFM_ServerInterface
final Server server = TotalFreedomMod.plugin.getServer(); final Server server = TotalFreedomMod.plugin.getServer();
final PlayerList player_list = MinecraftServer.getServer().getPlayerList(); final PlayerList playerList = MinecraftServer.getServer().getPlayerList();
final BanList banByIP = player_list.getIPBans(); final BanList banByIP = playerList.getIPBans();
final BanList banByName = player_list.getNameBans(); final BanList banByName = playerList.getNameBans();
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String player_name = player.getName(); final String username = player.getName();
final String player_ip = event.getAddress().getHostAddress().trim().toLowerCase(); final String ip = event.getAddress().getHostAddress().trim().toLowerCase();
if (player_name.trim().length() <= 2) if (username.trim().length() <= 2)
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long)."); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is too short (must be at least 3 characters long).");
return; return;
} }
else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(player_name).find()) else if (Pattern.compile("[^a-zA-Z0-9\\-\\.\\_]").matcher(username).find())
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters."); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username contains invalid characters.");
return; return;
} }
// not safe to use TFM_Util.isUserSuperadmin for player logging in because player.getAddress() will return a null until after player login. // not safe to use TFM_Util.isUserSuperadmin for player logging in because player.getAddress() will return a null until after player login.
boolean is_superadmin; boolean isSuperadmin;
if (server.getOnlineMode()) if (server.getOnlineMode())
{ {
is_superadmin = TFM_SuperadminList.getSuperadminNames().contains(player_name.toLowerCase()); isSuperadmin = TFM_SuperadminList.getSuperadminNames().contains(username.toLowerCase());
} }
else else
{ {
is_superadmin = TFM_SuperadminList.checkPartialSuperadminIP(player_ip, player_name.toLowerCase()); isSuperadmin = TFM_SuperadminList.checkPartialSuperadminIP(ip, username.toLowerCase());
} }
if (!is_superadmin) if (!isSuperadmin)
{ {
BanEntry ban_entry = null; BanEntry entry = null;
if (banByName.isBanned(player_name.toLowerCase())) if (banByName.isBanned(username.toLowerCase()))
{ {
ban_entry = (BanEntry) banByName.getEntries().get(player_name.toLowerCase()); entry = (BanEntry) banByName.getEntries().get(username.toLowerCase());
String kick_message = ChatColor.RED + "You are banned from this server."; String kickMessage = ChatColor.RED + "You are banned from this server.";
if (ban_entry != null) if (entry != null)
{ {
kick_message = kick_message + "\nReason: " + ban_entry.getReason(); kickMessage = kickMessage + "\nReason: " + entry.getReason();
if (ban_entry.getExpires() != null) if (entry.getExpires() != null)
{ {
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires()); kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(entry.getExpires());
} }
} }
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message); event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kickMessage);
return; return;
} }
boolean is_ip_banned = false; boolean isIpBanned = false;
Iterator ip_bans = banByIP.getEntries().keySet().iterator(); Iterator ipBans = banByIP.getEntries().keySet().iterator();
while (ip_bans.hasNext()) while (ipBans.hasNext())
{ {
String test_ip = (String) ip_bans.next(); String testIp = (String) ipBans.next();
if (!test_ip.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$")) if (!testIp.matches("^\\d{1,3}\\.\\d{1,3}\\.(\\d{1,3}|\\*)\\.(\\d{1,3}|\\*)$"))
{ {
continue; continue;
} }
if (player_ip.equals(test_ip)) if (ip.equals(testIp))
{ {
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip); entry = (BanEntry) banByIP.getEntries().get(testIp);
is_ip_banned = true; isIpBanned = true;
break; break;
} }
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4)) if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
{ {
ban_entry = (BanEntry) banByIP.getEntries().get(test_ip); entry = (BanEntry) banByIP.getEntries().get(testIp);
is_ip_banned = true; isIpBanned = true;
break; break;
} }
} }
if (is_ip_banned) if (isIpBanned)
{ {
String kick_message = ChatColor.RED + "Your IP address is banned from this server."; String kickMessage = ChatColor.RED + "Your IP address is banned from this server.";
if (ban_entry != null) if (entry != null)
{ {
kick_message = kick_message + "\nReason: " + ban_entry.getReason(); kickMessage = kickMessage + "\nReason: " + entry.getReason();
if (ban_entry.getExpires() != null) if (entry.getExpires() != null)
{ {
kick_message = kick_message + "\nYour ban will be removed on " + date_format.format(ban_entry.getExpires()); kickMessage = kickMessage + "\nYour ban will be removed on " + dateFormat.format(entry.getExpires());
} }
} }
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kick_message); event.disallow(PlayerLoginEvent.Result.KICK_BANNED, kickMessage);
return; return;
} }
for (String test_player : TotalFreedomMod.permbanned_players) for (String testPlayer : TotalFreedomMod.permbanned_players)
{ {
if (test_player.equalsIgnoreCase(player_name)) if (testPlayer.equalsIgnoreCase(username))
{ {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan"); event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your username is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan");
return; return;
} }
} }
for (String test_ip : TotalFreedomMod.permbanned_ips) for (String testIp : TotalFreedomMod.permbanned_ips)
{ {
if (TFM_Util.fuzzyIpMatch(test_ip, player_ip, 4)) if (TFM_Util.fuzzyIpMatch(testIp, ip, 4))
{ {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan"); event.disallow(PlayerLoginEvent.Result.KICK_BANNED, ChatColor.RED + "Your IP address is permanently banned from this server.\nRelease procedures are available at http://bit.ly/PermBan");
return; return;
@ -274,9 +274,9 @@ public class TFM_ServerInterface
return; return;
} }
if (player_list.hasWhitelist) if (playerList.hasWhitelist)
{ {
if (!player_list.getWhitelisted().contains(player_name.toLowerCase())) if (!playerList.getWhitelisted().contains(username.toLowerCase()))
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server."); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You are not whitelisted on this server.");
return; return;
@ -285,7 +285,7 @@ public class TFM_ServerInterface
for (Player test_player : server.getOnlinePlayers()) for (Player test_player : server.getOnlinePlayers())
{ {
if (test_player.getName().equalsIgnoreCase(player_name)) if (test_player.getName().equalsIgnoreCase(username))
{ {
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server."); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your username is already logged into this server.");
return; return;
@ -294,24 +294,24 @@ public class TFM_ServerInterface
} }
else else
{ {
for (Player test_player : server.getOnlinePlayers()) for (Player testPlayer : server.getOnlinePlayers())
{ {
if (test_player.getName().equalsIgnoreCase(player_name)) if (testPlayer.getName().equalsIgnoreCase(username))
{ {
test_player.kickPlayer("An admin just logged in with the username you are using."); testPlayer.kickPlayer("An admin just logged in with the username you are using.");
} }
} }
boolean can_kick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop. boolean canKick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick) while (server.getOnlinePlayers().length >= server.getMaxPlayers() && canKick)
{ {
can_kick = false; canKick = false;
for (Player test_player : server.getOnlinePlayers()) for (Player testPlayer : server.getOnlinePlayers())
{ {
if (!TFM_SuperadminList.isUserSuperadmin(test_player)) if (!TFM_SuperadminList.isUserSuperadmin(testPlayer))
{ {
can_kick = true; canKick = true;
test_player.kickPlayer("You have been kicked to free up room for an admin."); testPlayer.kickPlayer("You have been kicked to free up room for an admin.");
break; break;
} }
} }

View File

@ -49,21 +49,21 @@ public class TFM_ServiceChecker
try try
{ {
URL mojang_status = new URL(serviceCheckerURL); URL mojangStatus = new URL(serviceCheckerURL);
BufferedReader in = new BufferedReader(new InputStreamReader(mojang_status.openStream())); BufferedReader in = new BufferedReader(new InputStreamReader(mojangStatus.openStream()));
JSONArray status_json = (JSONArray) JSONValue.parse(in.readLine()); JSONArray statusJson = (JSONArray) JSONValue.parse(in.readLine());
in.close(); in.close();
TFM_ServiceChecker serviceChecker = TFM_ServiceChecker.getInstance(); TFM_ServiceChecker serviceChecker = TFM_ServiceChecker.getInstance();
Iterator status_it = status_json.iterator(); Iterator status_it = statusJson.iterator();
while (status_it.hasNext()) while (status_it.hasNext())
{ {
JSONObject service = (JSONObject) status_it.next(); JSONObject service = (JSONObject) status_it.next();
Iterator service_it = service.entrySet().iterator(); Iterator serviceIt = service.entrySet().iterator();
while (service_it.hasNext()) while (serviceIt.hasNext())
{ {
Entry<String, String> pair = (Entry<String, String>) service_it.next(); Entry<String, String> pair = (Entry<String, String>) serviceIt.next();
if ("lastcheck".equals(pair.getKey())) if ("lastcheck".equals(pair.getKey()))
{ {

View File

@ -8,33 +8,33 @@ import org.bukkit.configuration.ConfigurationSection;
public class TFM_Superadmin public class TFM_Superadmin
{ {
private final String name; private final String name;
private final String custom_login_message; private final String loginMessage;
private final boolean is_senior_admin; private final boolean isSeniorAdmin;
private final List<String> console_aliases; private final List<String> consoleAliases;
private List<String> ips; private List<String> ips;
private Date last_login; private Date lastLogin;
private boolean is_activated; private boolean isActivated;
public TFM_Superadmin(String name, List<String> ips, Date last_login, String custom_login_message, boolean is_senior_admin, List<String> console_aliases, boolean is_activated) public TFM_Superadmin(String name, List<String> ips, Date lastLogin, String loginMessage, boolean isSeniorAdmin, List<String> consoleAliases, boolean isActivated)
{ {
this.name = name.toLowerCase(); this.name = name.toLowerCase();
this.ips = ips; this.ips = ips;
this.last_login = last_login; this.lastLogin = lastLogin;
this.custom_login_message = custom_login_message; this.loginMessage = loginMessage;
this.is_senior_admin = is_senior_admin; this.isSeniorAdmin = isSeniorAdmin;
this.console_aliases = console_aliases; this.consoleAliases = consoleAliases;
this.is_activated = is_activated; this.isActivated = isActivated;
} }
public TFM_Superadmin(String name, ConfigurationSection section) public TFM_Superadmin(String name, ConfigurationSection section)
{ {
this.name = name.toLowerCase(); this.name = name.toLowerCase();
this.ips = section.getStringList("ips"); this.ips = section.getStringList("ips");
this.last_login = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L)))); this.lastLogin = TFM_Util.stringToDate(section.getString("last_login", TFM_Util.dateToString(new Date(0L))));
this.custom_login_message = section.getString("custom_login_message", ""); this.loginMessage = section.getString("custom_login_message", "");
this.is_senior_admin = section.getBoolean("is_senior_admin", false); this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
this.console_aliases = section.getStringList("console_aliases"); this.consoleAliases = section.getStringList("console_aliases");
this.is_activated = section.getBoolean("is_activated", true); this.isActivated = section.getBoolean("is_activated", true);
} }
@Override @Override
@ -46,11 +46,11 @@ public class TFM_Superadmin
{ {
output.append("Name: ").append(this.name).append("\n"); output.append("Name: ").append(this.name).append("\n");
output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n"); output.append("- IPs: ").append(StringUtils.join(this.ips, ", ")).append("\n");
output.append("- Last Login: ").append(TFM_Util.dateToString(this.last_login)).append("\n"); output.append("- Last Login: ").append(TFM_Util.dateToString(this.lastLogin)).append("\n");
output.append("- Custom Login Message: ").append(this.custom_login_message).append("\n"); output.append("- Custom Login Message: ").append(this.loginMessage).append("\n");
output.append("- Is Senior Admin: ").append(this.is_senior_admin).append("\n"); output.append("- Is Senior Admin: ").append(this.isSeniorAdmin).append("\n");
output.append("- Console Aliases: ").append(StringUtils.join(this.console_aliases, ", ")).append("\n"); output.append("- Console Aliases: ").append(StringUtils.join(this.consoleAliases, ", ")).append("\n");
output.append("- Is Activated: ").append(this.is_activated); output.append("- Is Activated: ").append(this.isActivated);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -72,22 +72,22 @@ public class TFM_Superadmin
public Date getLastLogin() public Date getLastLogin()
{ {
return last_login; return lastLogin;
} }
public String getCustomLoginMessage() public String getCustomLoginMessage()
{ {
return custom_login_message; return loginMessage;
} }
public boolean isSeniorAdmin() public boolean isSeniorAdmin()
{ {
return is_senior_admin; return isSeniorAdmin;
} }
public List<String> getConsoleAliases() public List<String> getConsoleAliases()
{ {
return console_aliases; return consoleAliases;
} }
public void setIps(List<String> ips) public void setIps(List<String> ips)
@ -95,18 +95,18 @@ public class TFM_Superadmin
this.ips = ips; this.ips = ips;
} }
public void setLastLogin(Date last_login) public void setLastLogin(Date lastLogin)
{ {
this.last_login = last_login; this.lastLogin = lastLogin;
} }
public boolean isActivated() public boolean isActivated()
{ {
return is_activated; return isActivated;
} }
public void setActivated(boolean is_activated) public void setActivated(boolean isActivated)
{ {
this.is_activated = is_activated; this.isActivated = isActivated;
} }
} }

View File

@ -25,7 +25,7 @@ public class TFM_SuperadminList
private static List<String> superadminNames = new ArrayList<String>(); private static List<String> superadminNames = new ArrayList<String>();
private static List<String> superadminIPs = new ArrayList<String>(); private static List<String> superadminIPs = new ArrayList<String>();
private static List<String> seniorAdminNames = new ArrayList<String>(); private static List<String> seniorAdminNames = new ArrayList<String>();
private static int clean_threshold_hours = 24 * 7; // 1 Week private static int cleanThreshold = 24 * 7; // 1 Week in hours
private TFM_SuperadminList() private TFM_SuperadminList()
{ {
@ -51,7 +51,7 @@ public class TFM_SuperadminList
TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file); TFM_Util.createDefaultConfiguration(TotalFreedomMod.SUPERADMIN_FILE, TotalFreedomMod.plugin_file);
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE)); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SUPERADMIN_FILE));
clean_threshold_hours = config.getInt("clean_threshold_hours", clean_threshold_hours); cleanThreshold = config.getInt("clean_threshold_hours", cleanThreshold);
if (config.isConfigurationSection("superadmins")) if (config.isConfigurationSection("superadmins"))
{ {
@ -133,7 +133,7 @@ public class TFM_SuperadminList
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
config.set("clean_threshold_hours", clean_threshold_hours); config.set("clean_threshold_hours", cleanThreshold);
Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator(); Iterator<Entry<String, TFM_Superadmin>> it = superadminList.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
@ -208,9 +208,9 @@ public class TFM_SuperadminList
return isSeniorAdmin(user, false); return isSeniorAdmin(user, false);
} }
public static boolean isSeniorAdmin(CommandSender user, boolean verify_is_superadmin) public static boolean isSeniorAdmin(CommandSender user, boolean verifySuperadmin)
{ {
if (verify_is_superadmin) if (verifySuperadmin)
{ {
if (!isUserSuperadmin(user)) if (!isUserSuperadmin(user))
{ {
@ -218,17 +218,17 @@ public class TFM_SuperadminList
} }
} }
String user_name = user.getName().toLowerCase(); String username = user.getName().toLowerCase();
if (!(user instanceof Player)) if (!(user instanceof Player))
{ {
return seniorAdminNames.contains(user_name); return seniorAdminNames.contains(username);
} }
TFM_Superadmin admin_entry = getAdminEntry((Player) user); TFM_Superadmin entry = getAdminEntry((Player) user);
if (admin_entry != null) if (entry != null)
{ {
return admin_entry.isSeniorAdmin(); return entry.isSeniorAdmin();
} }
return false; return false;
@ -251,10 +251,10 @@ public class TFM_SuperadminList
try try
{ {
String user_ip = ((Player) user).getAddress().getAddress().getHostAddress(); String ip = ((Player) user).getAddress().getAddress().getHostAddress();
if (user_ip != null && !user_ip.isEmpty()) if (ip != null && !ip.isEmpty())
{ {
if (superadminIPs.contains(user_ip)) if (superadminIPs.contains(ip))
{ {
return true; return true;
} }
@ -268,39 +268,39 @@ public class TFM_SuperadminList
return false; return false;
} }
public static boolean checkPartialSuperadminIP(String user_ip, String user_name) public static boolean checkPartialSuperadminIP(String ip, String name)
{ {
try try
{ {
user_ip = user_ip.trim(); ip = ip.trim();
if (superadminIPs.contains(user_ip)) if (superadminIPs.contains(ip))
{ {
return true; return true;
} }
else else
{ {
String match_ip = null; String matchIp = null;
for (String test_ip : getSuperadminIPs()) for (String testIp : getSuperadminIPs())
{ {
if (TFM_Util.fuzzyIpMatch(user_ip, test_ip, 3)) if (TFM_Util.fuzzyIpMatch(ip, testIp, 3))
{ {
match_ip = test_ip; matchIp = testIp;
break; break;
} }
} }
if (match_ip != null) if (matchIp != null)
{ {
TFM_Superadmin admin_entry = getAdminEntryByIP(match_ip); TFM_Superadmin entry = getAdminEntryByIP(matchIp);
if (admin_entry != null) if (entry != null)
{ {
if (admin_entry.getName().equalsIgnoreCase(user_name)) if (entry.getName().equalsIgnoreCase(name))
{ {
List<String> ips = admin_entry.getIps(); List<String> ips = entry.getIps();
ips.add(user_ip); ips.add(ip);
admin_entry.setIps(ips); entry.setIps(ips);
saveSuperadminList(); saveSuperadminList();
} }
} }
@ -334,28 +334,28 @@ public class TFM_SuperadminList
return false; return false;
} }
public static void addSuperadmin(String admin_name, List<String> ips) public static void addSuperadmin(String username, List<String> ips)
{ {
try try
{ {
admin_name = admin_name.toLowerCase(); username = username.toLowerCase();
if (superadminList.containsKey(admin_name)) if (superadminList.containsKey(username))
{ {
TFM_Superadmin superadmin = superadminList.get(admin_name); TFM_Superadmin superadmin = superadminList.get(username);
superadmin.setActivated(true); superadmin.setActivated(true);
superadmin.getIps().addAll(ips); superadmin.getIps().addAll(ips);
superadmin.setLastLogin(new Date()); superadmin.setLastLogin(new Date());
} }
else else
{ {
Date last_login = new Date(); Date lastLogin = new Date();
String custom_login_message = ""; String loginMessage = "";
boolean is_senior_admin = false; boolean isSeniorAdmin = false;
List<String> console_aliases = new ArrayList<String>(); List<String> consoleAliases = new ArrayList<String>();
TFM_Superadmin superadmin = new TFM_Superadmin(admin_name, ips, last_login, custom_login_message, is_senior_admin, console_aliases, true); TFM_Superadmin superadmin = new TFM_Superadmin(username, ips, lastLogin, loginMessage, isSeniorAdmin, consoleAliases, true);
superadminList.put(admin_name.toLowerCase(), superadmin); superadminList.put(username.toLowerCase(), superadmin);
} }
saveSuperadminList(); saveSuperadminList();
@ -368,26 +368,26 @@ public class TFM_SuperadminList
public static void addSuperadmin(Player player) public static void addSuperadmin(Player player)
{ {
String admin_name = player.getName().toLowerCase(); String username = player.getName().toLowerCase();
List<String> ips = Arrays.asList(player.getAddress().getAddress().getHostAddress()); List<String> ips = Arrays.asList(player.getAddress().getAddress().getHostAddress());
addSuperadmin(admin_name, ips); addSuperadmin(username, ips);
} }
public static void addSuperadmin(String admin_name) public static void addSuperadmin(String adminName)
{ {
addSuperadmin(admin_name, new ArrayList<String>()); addSuperadmin(adminName, new ArrayList<String>());
} }
public static void removeSuperadmin(String admin_name) public static void removeSuperadmin(String username)
{ {
try try
{ {
admin_name = admin_name.toLowerCase(); username = username.toLowerCase();
if (superadminList.containsKey(admin_name)) if (superadminList.containsKey(username))
{ {
TFM_Superadmin superadmin = superadminList.get(admin_name); TFM_Superadmin superadmin = superadminList.get(username);
superadmin.setActivated(false); superadmin.setActivated(false);
Command_logs.deactivateSuperadmin(superadmin); Command_logs.deactivateSuperadmin(superadmin);
saveSuperadminList(); saveSuperadminList();
@ -415,15 +415,15 @@ public class TFM_SuperadminList
TFM_Superadmin superadmin = pair.getValue(); TFM_Superadmin superadmin = pair.getValue();
if (superadmin.isActivated() && !superadmin.isSeniorAdmin()) if (superadmin.isActivated() && !superadmin.isSeniorAdmin())
{ {
Date last_login = superadmin.getLastLogin(); Date lastLogin = superadmin.getLastLogin();
long hours_since_login = TimeUnit.HOURS.convert(new Date().getTime() - last_login.getTime(), TimeUnit.MILLISECONDS); long lastLoginHours = TimeUnit.HOURS.convert(new Date().getTime() - lastLogin.getTime(), TimeUnit.MILLISECONDS);
if (hours_since_login > clean_threshold_hours) if (lastLoginHours > cleanThreshold)
{ {
if (verbose) if (verbose)
{ {
TFM_Util.adminAction("TotalFreedomSystem", "Deactivating superadmin \"" + superadmin.getName() + "\", inactive for " + hours_since_login + " hours.", true); TFM_Util.adminAction("TotalFreedomSystem", "Deactivating superadmin \"" + superadmin.getName() + "\", inactive for " + lastLoginHours + " hours.", true);
} }
superadmin.setActivated(false); superadmin.setActivated(false);
@ -439,17 +439,17 @@ public class TFM_SuperadminList
} }
} }
public static boolean verifyIdentity(String admin_name, String ip) throws Exception public static boolean verifyIdentity(String username, String ip) throws Exception
{ {
if (Bukkit.getOnlineMode()) if (Bukkit.getOnlineMode())
{ {
return true; return true;
} }
TFM_Superadmin admin_entry = getAdminEntry(admin_name); TFM_Superadmin entry = getAdminEntry(username);
if (admin_entry != null) if (entry != null)
{ {
return admin_entry.getIps().contains(ip); return entry.getIps().contains(ip);
} }
else else
{ {

View File

@ -32,11 +32,11 @@ public class TFM_UserList
{ {
userlist.clear(); userlist.clear();
FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), USERLIST_FILENAME)); FileConfiguration savedUserlist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), USERLIST_FILENAME));
for (String username : saved_userlist.getKeys(false)) for (String username : savedUserlist.getKeys(false))
{ {
TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username)); TFM_UserListEntry entry = new TFM_UserListEntry(username, savedUserlist.getStringList(username));
userlist.put(username, entry); userlist.put(username, entry);
} }
@ -56,16 +56,16 @@ public class TFM_UserList
private void exportList() private void exportList()
{ {
FileConfiguration new_userlist = new YamlConfiguration(); FileConfiguration newUserlist = new YamlConfiguration();
for (TFM_UserListEntry entry : userlist.values()) for (TFM_UserListEntry entry : userlist.values())
{ {
new_userlist.set(entry.getUsername(), entry.getIpAddresses()); newUserlist.set(entry.getUsername(), entry.getIpAddresses());
} }
try try
{ {
new_userlist.save(new File(plugin.getDataFolder(), USERLIST_FILENAME)); newUserlist.save(new File(plugin.getDataFolder(), USERLIST_FILENAME));
} }
catch (IOException ex) catch (IOException ex)
{ {
@ -87,7 +87,7 @@ public class TFM_UserList
addUser(player.getName(), player.getAddress().getAddress().getHostAddress()); addUser(player.getName(), player.getAddress().getAddress().getHostAddress());
} }
public void addUser(String username, String ip_address) public void addUser(String username, String ip)
{ {
username = username.toLowerCase(); username = username.toLowerCase();
@ -99,7 +99,7 @@ public class TFM_UserList
userlist.put(username, entry); userlist.put(username, entry);
if (entry.addIpAddress(ip_address)) if (entry.addIpAddress(ip))
{ {
exportList(); exportList();
} }
@ -149,12 +149,12 @@ public class TFM_UserList
public class TFM_UserListEntry public class TFM_UserListEntry
{ {
private String username; private String username;
private List<String> ip_addresses = new ArrayList<String>(); private List<String> ipAddresses = new ArrayList<String>();
public TFM_UserListEntry(String username, List<String> ip_addresses) public TFM_UserListEntry(String username, List<String> ipAddresses)
{ {
this.username = username; this.username = username;
this.ip_addresses = ip_addresses; this.ipAddresses = ipAddresses;
} }
public TFM_UserListEntry(String username) public TFM_UserListEntry(String username)
@ -164,7 +164,7 @@ public class TFM_UserList
public List<String> getIpAddresses() public List<String> getIpAddresses()
{ {
return ip_addresses; return ipAddresses;
} }
public String getUsername() public String getUsername()
@ -172,11 +172,11 @@ public class TFM_UserList
return username; return username;
} }
public boolean addIpAddress(String ip_address) public boolean addIpAddress(String ip)
{ {
if (!ip_addresses.contains(ip_address)) if (!ipAddresses.contains(ip))
{ {
ip_addresses.add(ip_address); ipAddresses.add(ip);
return true; return true;
} }
return false; return false;

View File

@ -21,7 +21,7 @@ import org.bukkit.entity.*;
public class TFM_Util public class TFM_Util
{ {
private static final Map<String, Integer> eject_tracker = new HashMap<String, Integer>(); private static final Map<String, Integer> ejectTracker = new HashMap<String, Integer>();
public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>(); public static final Map<String, EntityType> mobtypes = new HashMap<String, EntityType>();
public static final List<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die"); public static final List<String> STOP_COMMANDS = Arrays.asList("stop", "off", "end", "halt", "die");
public static final List<String> REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove"); public static final List<String> REMOVE_COMMANDS = Arrays.asList("del", "delete", "rem", "remove");
@ -29,15 +29,15 @@ public class TFM_Util
static static
{ {
for (EntityType entity_type : EntityType.values()) for (EntityType type : EntityType.values())
{ {
try try
{ {
if (entity_type.getName() != null) if (type.getName() != null)
{ {
if (Creature.class.isAssignableFrom(entity_type.getEntityClass())) if (Creature.class.isAssignableFrom(type.getEntityClass()))
{ {
mobtypes.put(entity_type.getName().toLowerCase(), entity_type); mobtypes.put(type.getName().toLowerCase(), type);
} }
} }
} }
@ -84,25 +84,25 @@ public class TFM_Util
TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA)); TFM_Util.bcastMsg(adminName + " - " + action, (isRed ? ChatColor.RED : ChatColor.AQUA));
} }
public static String formatLocation(Location in_loc) public static String formatLocation(Location location)
{ {
return String.format("%s: (%d, %d, %d)", return String.format("%s: (%d, %d, %d)",
in_loc.getWorld().getName(), location.getWorld().getName(),
Math.round(in_loc.getX()), Math.round(location.getX()),
Math.round(in_loc.getY()), Math.round(location.getY()),
Math.round(in_loc.getZ())); Math.round(location.getZ()));
} }
public static void gotoWorld(CommandSender sender, String targetworld) public static void gotoWorld(CommandSender sender, String targetworld)
{ {
if (sender instanceof Player) if (sender instanceof Player)
{ {
Player sender_p = (Player) sender; Player player = (Player) sender;
if (sender_p.getWorld().getName().equalsIgnoreCase(targetworld)) if (player.getWorld().getName().equalsIgnoreCase(targetworld))
{ {
sender.sendMessage(ChatColor.GRAY + "Going to main world."); sender.sendMessage(ChatColor.GRAY + "Going to main world.");
sender_p.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
return; return;
} }
@ -111,7 +111,7 @@ public class TFM_Util
if (world.getName().equalsIgnoreCase(targetworld)) if (world.getName().equalsIgnoreCase(targetworld))
{ {
sender.sendMessage(ChatColor.GRAY + "Going to world: " + targetworld); sender.sendMessage(ChatColor.GRAY + "Going to world: " + targetworld);
sender_p.teleport(world.getSpawnLocation()); player.teleport(world.getSpawnLocation());
return; return;
} }
} }
@ -126,14 +126,14 @@ public class TFM_Util
public static void buildHistory(Location location, int length, TFM_PlayerData playerdata) public static void buildHistory(Location location, int length, TFM_PlayerData playerdata)
{ {
Block center_block = location.getBlock(); Block center = location.getBlock();
for (int x_offset = -length; x_offset <= length; x_offset++) for (int xOffset = -length; xOffset <= length; xOffset++)
{ {
for (int y_offset = -length; y_offset <= length; y_offset++) for (int yOffset = -length; yOffset <= length; yOffset++)
{ {
for (int z_offset = -length; z_offset <= length; z_offset++) for (int zOffset = -length; zOffset <= length; zOffset++)
{ {
Block block = center_block.getRelative(x_offset, y_offset, z_offset); Block block = center.getRelative(xOffset, yOffset, zOffset);
playerdata.insertHistoryBlock(block.getLocation(), block.getType()); playerdata.insertHistoryBlock(block.getLocation(), block.getType());
} }
} }
@ -142,14 +142,14 @@ public class TFM_Util
public static void generateCube(Location location, int length, Material material) public static void generateCube(Location location, int length, Material material)
{ {
Block center_block = location.getBlock(); Block block = location.getBlock();
for (int x_offset = -length; x_offset <= length; x_offset++) for (int xOffset = -length; xOffset <= length; xOffset++)
{ {
for (int y_offset = -length; y_offset <= length; y_offset++) for (int yOffset = -length; yOffset <= length; yOffset++)
{ {
for (int z_offset = -length; z_offset <= length; z_offset++) for (int zOffset = -length; zOffset <= length; zOffset++)
{ {
center_block.getRelative(x_offset, y_offset, z_offset).setType(material); block.getRelative(xOffset, yOffset, zOffset).setType(material);
} }
} }
} }
@ -162,7 +162,7 @@ public class TFM_Util
world.setTime(time + 24000 + ticks); world.setTime(time + 24000 + ticks);
} }
public static void createDefaultConfiguration(String name, File plugin_file) public static void createDefaultConfiguration(String name, File pluginFile)
{ {
TotalFreedomMod tfm = TotalFreedomMod.plugin; TotalFreedomMod tfm = TotalFreedomMod.plugin;
@ -173,7 +173,7 @@ public class TFM_Util
InputStream input = null; InputStream input = null;
try try
{ {
JarFile file = new JarFile(plugin_file); JarFile file = new JarFile(pluginFile);
ZipEntry copy = file.getEntry(name); ZipEntry copy = file.getEntry(name);
if (copy == null) if (copy == null)
{ {
@ -405,31 +405,31 @@ public class TFM_Util
public static void autoEject(Player player, String kickMessage) public static void autoEject(Player player, String kickMessage)
{ {
EjectMethod method = EjectMethod.STRIKE_ONE; EjectMethod method = EjectMethod.STRIKE_ONE;
String player_ip = null; String ip = null;
try try
{ {
player_ip = player.getAddress().getAddress().getHostAddress(); ip = player.getAddress().getAddress().getHostAddress();
Integer num_kicks = TFM_Util.eject_tracker.get(player_ip); Integer kicks = TFM_Util.ejectTracker.get(ip);
if (num_kicks == null) if (kicks == null)
{ {
num_kicks = new Integer(0); kicks = new Integer(0);
} }
num_kicks = new Integer(num_kicks.intValue() + 1); kicks = new Integer(kicks.intValue() + 1);
TFM_Util.eject_tracker.put(player_ip, num_kicks); TFM_Util.ejectTracker.put(ip, kicks);
if (num_kicks.intValue() <= 1) if (kicks.intValue() <= 1)
{ {
method = EjectMethod.STRIKE_ONE; method = EjectMethod.STRIKE_ONE;
} }
else if (num_kicks.intValue() == 2) else if (kicks.intValue() == 2)
{ {
method = EjectMethod.STRIKE_TWO; method = EjectMethod.STRIKE_TWO;
} }
else if (num_kicks.intValue() >= 3) else if (kicks.intValue() >= 3)
{ {
method = EjectMethod.STRIKE_THREE; method = EjectMethod.STRIKE_THREE;
} }
@ -438,7 +438,7 @@ public class TFM_Util
{ {
} }
TFM_Log.info("autoEject -> name: " + player.getName() + " - player_ip: " + player_ip + " - method: " + method.toString()); TFM_Log.info("autoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString());
player.setOp(false); player.setOp(false);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
@ -454,7 +454,7 @@ public class TFM_Util
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute."); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
TFM_ServerInterface.banIP(player_ip, kickMessage, "AutoEject", expires); TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", expires);
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires); TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires);
player.kickPlayer(kickMessage); player.kickPlayer(kickMessage);
@ -468,7 +468,7 @@ public class TFM_Util
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes."); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
TFM_ServerInterface.banIP(player_ip, kickMessage, "AutoEject", expires); TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", expires);
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires); TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", expires);
player.kickPlayer(kickMessage); player.kickPlayer(kickMessage);
@ -477,10 +477,10 @@ public class TFM_Util
case STRIKE_THREE: case STRIKE_THREE:
{ {
//Bukkit.banIP(player_ip); //Bukkit.banIP(player_ip);
TFM_ServerInterface.banIP(player_ip, kickMessage, "AutoEject", null); TFM_ServerInterface.banIP(ip, kickMessage, "AutoEject", null);
String[] ip_address_parts = player_ip.split("\\."); String[] ipAddressParts = ip.split("\\.");
//Bukkit.banIP(); //Bukkit.banIP();
TFM_ServerInterface.banIP(ip_address_parts[0] + "." + ip_address_parts[1] + ".*.*", kickMessage, "AutoEject", null); TFM_ServerInterface.banIP(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", kickMessage, "AutoEject", null);
//p.setBanned(true); //p.setBanned(true);
TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", null); TFM_ServerInterface.banUsername(player.getName(), kickMessage, "AutoEject", null);
@ -501,23 +501,23 @@ public class TFM_Util
return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!"; return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!";
} }
TFM_Superadmin admin_entry = TFM_SuperadminList.getAdminEntry(sender.getName()); TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName());
if (admin_entry != null) if (entry != null)
{ {
if (admin_entry.isActivated()) if (entry.isActivated())
{ {
String custom_login_message = admin_entry.getCustomLoginMessage(); String loginMessage = entry.getCustomLoginMessage();
if (custom_login_message != null) if (loginMessage != null)
{ {
if (!custom_login_message.isEmpty()) if (!loginMessage.isEmpty())
{ {
return ChatColor.translateAlternateColorCodes('&', custom_login_message); return ChatColor.translateAlternateColorCodes('&', loginMessage);
} }
} }
if (admin_entry.isSeniorAdmin()) if (entry.isSeniorAdmin())
{ {
return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + "."; return "a " + ChatColor.LIGHT_PURPLE + "Senior Admin" + ChatColor.AQUA + ".";
} }
@ -643,27 +643,27 @@ public class TFM_Util
public static String playerListToNames(Set<OfflinePlayer> players) public static String playerListToNames(Set<OfflinePlayer> players)
{ {
List<String> player_names = new ArrayList<String>(); List<String> names = new ArrayList<String>();
for (OfflinePlayer player : players) for (OfflinePlayer player : players)
{ {
player_names.add(player.getName()); names.add(player.getName());
} }
return StringUtils.join(player_names, ", "); return StringUtils.join(names, ", ");
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Map<String, Boolean> getSavedFlags() public static Map<String, Boolean> getSavedFlags()
{ {
Map<String, Boolean> saved_flags = null; Map<String, Boolean> flags = null;
File input_file = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE); File input = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE);
if (input_file.exists()) if (input.exists())
{ {
try try
{ {
FileInputStream fis = new FileInputStream(input_file); FileInputStream fis = new FileInputStream(input);
ObjectInputStream ois = new ObjectInputStream(fis); ObjectInputStream ois = new ObjectInputStream(fis);
saved_flags = (HashMap<String, Boolean>) ois.readObject(); flags = (HashMap<String, Boolean>) ois.readObject();
ois.close(); ois.close();
fis.close(); fis.close();
} }
@ -673,26 +673,26 @@ public class TFM_Util
} }
} }
return saved_flags; return flags;
} }
public static boolean getSavedFlag(String flag) throws Exception public static boolean getSavedFlag(String flag) throws Exception
{ {
Boolean flag_value = null; Boolean flagValue = null;
Map<String, Boolean> saved_flags = TFM_Util.getSavedFlags(); Map<String, Boolean> flags = TFM_Util.getSavedFlags();
if (saved_flags != null) if (flags != null)
{ {
if (saved_flags.containsKey(flag)) if (flags.containsKey(flag))
{ {
flag_value = saved_flags.get(flag); flagValue = flags.get(flag);
} }
} }
if (flag_value != null) if (flagValue != null)
{ {
return flag_value.booleanValue(); return flagValue.booleanValue();
} }
else else
{ {
@ -702,20 +702,20 @@ public class TFM_Util
public static void setSavedFlag(String flag, boolean value) public static void setSavedFlag(String flag, boolean value)
{ {
Map<String, Boolean> saved_flags = TFM_Util.getSavedFlags(); Map<String, Boolean> flags = TFM_Util.getSavedFlags();
if (saved_flags == null) if (flags == null)
{ {
saved_flags = new HashMap<String, Boolean>(); flags = new HashMap<String, Boolean>();
} }
saved_flags.put(flag, value); flags.put(flag, value);
try try
{ {
FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE)); FileOutputStream fos = new FileOutputStream(new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILE));
ObjectOutputStream oos = new ObjectOutputStream(fos); ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(saved_flags); oos.writeObject(flags);
oos.close(); oos.close();
fos.close(); fos.close();
} }
@ -731,92 +731,92 @@ public class TFM_Util
return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).format(date); return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).format(date);
} }
public static Date stringToDate(String date_str) public static Date stringToDate(String dateString)
{ {
try try
{ {
return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).parse(date_str); return new SimpleDateFormat(DATE_STORAGE_FORMAT, Locale.ENGLISH).parse(dateString);
} }
catch (ParseException ex) catch (ParseException pex)
{ {
return new Date(0L); return new Date(0L);
} }
} }
public static boolean isFromHostConsole(String sender_name) public static boolean isFromHostConsole(String senderName)
{ {
return ((List<String>) TFM_ConfigEntry.HOST_SENDER_NAMES.getList()).contains(sender_name.toLowerCase()); return ((List<String>) TFM_ConfigEntry.HOST_SENDER_NAMES.getList()).contains(senderName.toLowerCase());
} }
public static List<String> removeDuplicates(List<String> old_list) public static List<String> removeDuplicates(List<String> oldList)
{ {
List<String> new_list = new ArrayList<String>(); List<String> newList = new ArrayList<String>();
for (String entry : old_list) for (String entry : oldList)
{ {
if (!new_list.contains(entry)) if (!newList.contains(entry))
{ {
new_list.add(entry); newList.add(entry);
} }
} }
return new_list; return newList;
} }
public static boolean fuzzyIpMatch(String a, String b, int required_octets) public static boolean fuzzyIpMatch(String a, String b, int octets)
{ {
boolean is_match = true; boolean match = true;
String[] a_parts = a.split("\\."); String[] aParts = a.split("\\.");
String[] b_parts = b.split("\\."); String[] bParts = b.split("\\.");
if (a_parts.length != 4 || b_parts.length != 4) if (aParts.length != 4 || bParts.length != 4)
{ {
return false; return false;
} }
if (required_octets > 4) if (octets > 4)
{ {
required_octets = 4; octets = 4;
} }
else if (required_octets < 1) else if (octets < 1)
{ {
required_octets = 1; octets = 1;
} }
for (int i = 0; i < required_octets && i < 4; i++) for (int i = 0; i < octets && i < 4; i++)
{ {
if (a_parts[i].equals("*") || b_parts[i].equals("*")) if (aParts[i].equals("*") || bParts[i].equals("*"))
{ {
continue; continue;
} }
if (!a_parts[i].equals(b_parts[i])) if (!aParts[i].equals(bParts[i]))
{ {
is_match = false; match = false;
break; break;
} }
} }
return is_match; return match;
} }
public static int replaceBlocks(Location center_location, Material from_material, Material to_material, int radius) public static int replaceBlocks(Location center, Material fromMaterial, Material toMaterial, int radius)
{ {
int affected = 0; int affected = 0;
Block center_block = center_location.getBlock(); Block centerBlock = center.getBlock();
for (int x_offset = -radius; x_offset <= radius; x_offset++) for (int xOffset = -radius; xOffset <= radius; xOffset++)
{ {
for (int y_offset = -radius; y_offset <= radius; y_offset++) for (int yOffset = -radius; yOffset <= radius; yOffset++)
{ {
for (int z_offset = -radius; z_offset <= radius; z_offset++) for (int zOffset = -radius; zOffset <= radius; zOffset++)
{ {
Block test_block = center_block.getRelative(x_offset, y_offset, z_offset); Block block = centerBlock.getRelative(xOffset, yOffset, zOffset);
if (test_block.getType().equals(from_material)) if (block.getType().equals(fromMaterial))
{ {
if (test_block.getLocation().distanceSquared(center_location) < (radius * radius)) if (block.getLocation().distanceSquared(center) < (radius * radius))
{ {
test_block.setType(to_material); block.setType(toMaterial);
affected++; affected++;
} }
} }
@ -827,22 +827,22 @@ public class TFM_Util
return affected; return affected;
} }
public static void downloadFile(String url, File output_file) throws java.lang.Exception public static void downloadFile(String url, File output) throws java.lang.Exception
{ {
downloadFile(url, output_file, false); downloadFile(url, output, false);
} }
public static void downloadFile(String url, File output_file, boolean verbose) throws java.lang.Exception public static void downloadFile(String url, File output, boolean verbose) throws java.lang.Exception
{ {
URL website = new URL(url); URL website = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(output_file); FileOutputStream fos = new FileOutputStream(output);
fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close(); fos.close();
if (verbose) if (verbose)
{ {
TFM_Log.info("Downloaded " + url + " to " + output_file.toString() + "."); TFM_Log.info("Downloaded " + url + " to " + output.toString() + ".");
} }
} }