More fun code cleanup.

This commit is contained in:
Steven Lawson 2011-10-13 19:45:01 -04:00
parent 85f32fcc76
commit d5d0bd1a26
5 changed files with 66 additions and 63 deletions

View File

@ -46,11 +46,11 @@ public class TFM_BlockListener extends BlockListener
{
Player p = event.getPlayer();
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata == null)
{
playerdata = new TFM_UserInfo();
TotalFreedomMod.userinfo.put(p, playerdata);
plugin.userinfo.put(p, playerdata);
}
Location player_pos = p.getLocation();
@ -101,11 +101,11 @@ public class TFM_BlockListener extends BlockListener
if (player_pos.distance(block_pos) > plugin.nukeMonitorRange)
{
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata == null)
{
playerdata = new TFM_UserInfo();
TotalFreedomMod.userinfo.put(p, playerdata);
plugin.userinfo.put(p, playerdata);
}
playerdata.incrementFreecamPlaceCount();

View File

@ -81,7 +81,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
p = matches.get(0);
}
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata != null)
{
playerdata.setFrozen(!playerdata.isFrozen());
@ -90,7 +90,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
{
playerdata = new TFM_UserInfo();
playerdata.setFrozen(true);
TotalFreedomMod.userinfo.put(p, playerdata);
plugin.userinfo.put(p, playerdata);
}
sender.sendMessage(ChatColor.AQUA + p.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
@ -239,7 +239,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
}
else if (mode.equals("fr"))
{
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata != null)
{
playerdata.setFrozen(!playerdata.isFrozen());
@ -248,7 +248,7 @@ public class TFM_Cmds_Admin implements CommandExecutor
{
playerdata = new TFM_UserInfo();
playerdata.setFrozen(true);
TotalFreedomMod.userinfo.put(p, playerdata);
plugin.userinfo.put(p, playerdata);
}
sender.sendMessage(ChatColor.AQUA + p.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
p.sendMessage(ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
@ -586,11 +586,11 @@ public class TFM_Cmds_Admin implements CommandExecutor
p = matches.get(0);
}
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata == null)
{
playerdata = new TFM_UserInfo();
TotalFreedomMod.userinfo.put(p, playerdata);
plugin.userinfo.put(p, playerdata);
}
Material cage_material_outer = Material.GLASS;

View File

@ -0,0 +1,45 @@
package me.StevenLawson.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class TFM_Heartbeat implements Runnable
{
private TotalFreedomMod plugin;
TFM_Heartbeat(TotalFreedomMod instance)
{
this.plugin = instance;
}
@Override
public void run()
{
for (Player p : Bukkit.getOnlinePlayers())
{
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata != null)
{
playerdata.resetMsgCount();
playerdata.resetBlockDestroyCount();
}
}
if (plugin.autoEntityWipe)
{
TFM_Util.wipeDropEntities(plugin);
}
if (plugin.disableNight)
{
for (World world : Bukkit.getWorlds())
{
if (world.getTime() > 12000L)
{
TFM_Util.setWorldTime(world, 1000L);
}
}
}
}
}

View File

@ -57,7 +57,7 @@ class TFM_PlayerListener extends PlayerListener
public void onPlayerMove(PlayerMoveEvent event)
{
Player p = event.getPlayer();
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
boolean do_freeze = false;
if (plugin.allPlayersFrozen)
@ -114,7 +114,7 @@ class TFM_PlayerListener extends PlayerListener
{
Player p = event.getPlayer();
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
TFM_UserInfo playerdata = plugin.userinfo.get(p);
if (playerdata != null)
{
playerdata.incrementMsgCount();
@ -133,7 +133,7 @@ class TFM_PlayerListener extends PlayerListener
{
playerdata = new TFM_UserInfo();
playerdata.incrementMsgCount();
TotalFreedomMod.userinfo.put(p, playerdata);
plugin.userinfo.put(p, playerdata);
}
}

View File

@ -9,7 +9,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -19,24 +18,19 @@ import org.bukkit.plugin.java.JavaPlugin;
public class TotalFreedomMod extends JavaPlugin
{
public TotalFreedomMod tfm = this;
private final TFM_EntityListener entityListener = new TFM_EntityListener(this);
private final TFM_BlockListener blockListener = new TFM_BlockListener(this);
private final TFM_PlayerListener playerListener = new TFM_PlayerListener(this);
private static final Logger log = Logger.getLogger("Minecraft");
public boolean allPlayersFrozen = false;
public static Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>();
public static final long HEARTBEAT_RATE = 5L; //Seconds
public static final String CONFIG_FILE = "config.yml";
public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
public static final String YOU_ARE_OP = ChatColor.YELLOW + "You are now op!";
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer op!";
public static final String CAKE_LYRICS = "But there's no sense crying over every mistake. You just keep on trying till you run out of cake.";
public Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>();
public boolean allPlayersFrozen = false;
@Override
public void onEnable()
{
@ -56,46 +50,6 @@ public class TotalFreedomMod extends JavaPlugin
log.log(Level.INFO, "[" + getDescription().getName() + "] - Disabled.");
}
class TFM_Heartbeat implements Runnable
{
private TotalFreedomMod plugin;
TFM_Heartbeat(TotalFreedomMod instance)
{
this.plugin = instance;
}
@Override
public void run()
{
for (Player p : Bukkit.getOnlinePlayers())
{
TFM_UserInfo playerdata = TotalFreedomMod.userinfo.get(p);
if (playerdata != null)
{
playerdata.resetMsgCount();
playerdata.resetBlockDestroyCount();
}
}
if (plugin.autoEntityWipe)
{
TFM_Util.wipeDropEntities(plugin);
}
if (plugin.disableNight)
{
for (World world : Bukkit.getWorlds())
{
if (world.getTime() > 12000L)
{
TFM_Util.setWorldTime(world, 1000L);
}
}
}
}
}
public boolean allowFirePlace = false;
public Boolean allowFireSpread = false;
public Boolean allowLavaDamage = false;
@ -150,6 +104,10 @@ public class TotalFreedomMod extends JavaPlugin
}
}
private final TFM_EntityListener entityListener = new TFM_EntityListener(this);
private final TFM_BlockListener blockListener = new TFM_BlockListener(this);
private final TFM_PlayerListener playerListener = new TFM_PlayerListener(this);
private void registerEventHandlers()
{
PluginManager pm = this.getServer().getPluginManager();