Changing over to new config API.

This commit is contained in:
Steven Lawson 2011-10-12 14:13:10 -04:00
parent 112382893d
commit b8d5e2f974
3 changed files with 118 additions and 60 deletions

View File

@ -26,7 +26,7 @@ dist.jar=${dist.dir}/TotalFreedomMod.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath= endorsed.classpath=
excludes= excludes=
file.reference.bukkit-0.0.1-SNAPSHOT.jar=C:\\github\\Bukkit\\target\\bukkit-0.0.1-SNAPSHOT.jar file.reference.bukkit-0.0.1-SNAPSHOT.jar=C:\\github\\bukkit-0.0.1-SNAPSHOT.jar
file.reference.MobDisguise.jar=C:\\github\\MobDisguise\\dist\\MobDisguise.jar file.reference.MobDisguise.jar=C:\\github\\MobDisguise\\dist\\MobDisguise.jar
includes=** includes=**
jar.compress=false jar.compress=false

View File

@ -337,11 +337,11 @@ public class TFM_Cmds_Admin implements CommandExecutor
sender.sendMessage("Nuke monitor is disabled."); sender.sendMessage("Nuke monitor is disabled.");
} }
TotalFreedomMod.CONFIG.load(); plugin.reloadConfig();
TotalFreedomMod.CONFIG.setProperty("nuke_monitor", plugin.nukeMonitor); plugin.getConfig().set("nuke_monitor", plugin.nukeMonitor);
TotalFreedomMod.CONFIG.setProperty("nuke_monitor_range", plugin.nukeMonitorRange); plugin.getConfig().set("nuke_monitor_range", plugin.nukeMonitorRange);
TotalFreedomMod.CONFIG.setProperty("nuke_monitor_count", plugin.nukeMonitorCountBreak); plugin.getConfig().set("nuke_monitor_count", plugin.nukeMonitorCountBreak);
TotalFreedomMod.CONFIG.save(); plugin.saveConfig();
} }
else else
{ {
@ -369,10 +369,10 @@ public class TFM_Cmds_Admin implements CommandExecutor
plugin.preprocessLogEnabled = false; plugin.preprocessLogEnabled = false;
sender.sendMessage("Command preprocess logging is now disabled."); sender.sendMessage("Command preprocess logging is now disabled.");
} }
TotalFreedomMod.CONFIG.load(); plugin.reloadConfig();
TotalFreedomMod.CONFIG.setProperty("preprocess_log", plugin.preprocessLogEnabled); plugin.getConfig().set("preprocess_log", plugin.preprocessLogEnabled);
TotalFreedomMod.CONFIG.save(); plugin.saveConfig();
} }
else else
{ {

View File

@ -1,13 +1,18 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.jar.JarFile;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -19,7 +24,6 @@ import org.bukkit.entity.*;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
public class TotalFreedomMod extends JavaPlugin public class TotalFreedomMod extends JavaPlugin
{ {
@ -31,7 +35,6 @@ public class TotalFreedomMod extends JavaPlugin
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
protected static Configuration CONFIG;
public List<String> superadmins = new ArrayList<String>(); public List<String> superadmins = new ArrayList<String>();
public List<String> superadmin_ips = new ArrayList<String>(); public List<String> superadmin_ips = new ArrayList<String>();
public Boolean allowExplosions = false; public Boolean allowExplosions = false;
@ -48,9 +51,6 @@ public class TotalFreedomMod extends JavaPlugin
public Boolean preprocessLogEnabled = false; public Boolean preprocessLogEnabled = false;
public int freecamTriggerCount = 10; public int freecamTriggerCount = 10;
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 long HEARTBEAT_RATE = 5L; //Seconds
public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command."; public static final String MSG_NO_PERMS = ChatColor.YELLOW + "You do not have permission to use this command.";
@ -58,6 +58,9 @@ public class TotalFreedomMod extends JavaPlugin
public static final String YOU_ARE_NOT_OP = ChatColor.YELLOW + "You are no longer 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 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 boolean allPlayersFrozen = false;
public static Map<Player, TFM_UserInfo> userinfo = new HashMap<Player, TFM_UserInfo>();
private TFM_Cmds_OP OPCommands = new TFM_Cmds_OP(this); private TFM_Cmds_OP OPCommands = new TFM_Cmds_OP(this);
private TFM_Cmds_Override OverrideCommands = new TFM_Cmds_Override(this); private TFM_Cmds_Override OverrideCommands = new TFM_Cmds_Override(this);
private TFM_Cmds_General GeneralCommands = new TFM_Cmds_General(this); private TFM_Cmds_General GeneralCommands = new TFM_Cmds_General(this);
@ -67,7 +70,6 @@ public class TotalFreedomMod extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
CONFIG = getConfiguration();
loadConfig(); loadConfig();
registerEventHandlers(); registerEventHandlers();
@ -217,49 +219,105 @@ public class TotalFreedomMod extends JavaPlugin
private void loadConfig() private void loadConfig()
{ {
File configfile = new File("plugins/TotalFreedomMod/config.yml"); createDefaultConfiguration("config.yml");
if (!configfile.exists())
reloadConfig();
allowExplosions = getConfig().getBoolean("allow_explosions", false);
allowFirePlace = getConfig().getBoolean("allow_fire_place", false);
allowFireSpread = getConfig().getBoolean("allow_fire_spread", false);
allowLavaDamage = getConfig().getBoolean("allow_lava_damage", false);
allowLavaPlace = getConfig().getBoolean("allow_lava_place", false);
allowWaterPlace = getConfig().getBoolean("allow_water_place", false);
autoEntityWipe = getConfig().getBoolean("auto_wipe", true);
explosiveRadius = getConfig().getDouble("explosiveRadius", 4.0D);
nukeMonitor = getConfig().getBoolean("nuke_monitor", true);
nukeMonitorCountBreak = getConfig().getInt("nuke_monitor_count", 100);
nukeMonitorRange = getConfig().getDouble("nuke_monitor_range", 10.0D);
preprocessLogEnabled = getConfig().getBoolean("preprocess_log", true);
freecamTriggerCount = getConfig().getInt("freecam_trigger_count", 10);
superadmins = (List<String>) getConfig().getList("superadmins", null);
if (superadmins == null)
{ {
log.log(Level.INFO, "[Total Freedom Mod] - Generating default config file (plugins/TotalFreedomMod/config.yml)..."); superadmins = new ArrayList<String>();
CONFIG.setProperty("superadmins", new String[] superadmins.add("Madgeek1450");
{ superadmins.add("markbyron");
"Madgeek1450", "markbyron" }
});
CONFIG.setProperty("superadmin_ips", new String[] superadmin_ips = (List<String>) getConfig().getList("superadmin_ips", null);
{ if (superadmin_ips == null)
"0.0.0.0" {
}); superadmin_ips = new ArrayList<String>();
CONFIG.setProperty("allow_explosions", false); }
CONFIG.setProperty("allow_fire_place", false); }
CONFIG.setProperty("allow_fire_spread", false);
CONFIG.setProperty("allow_lava_damage", false); private void createDefaultConfiguration(String name)
CONFIG.setProperty("allow_lava_place", false); {
CONFIG.setProperty("allow_water_place", false); File actual = new File(getDataFolder(), name);
CONFIG.setProperty("auto_wipe", false); if (!actual.exists())
CONFIG.setProperty("explosiveRadius", 4.0D); {
CONFIG.setProperty("nuke_monitor", true); InputStream input = null;
CONFIG.setProperty("nuke_monitor_count", 40); try
CONFIG.setProperty("nuke_monitor_range", 10.0D); {
CONFIG.setProperty("preprocess_log", false); JarFile file = new JarFile(getFile());
CONFIG.setProperty("freecam_trigger_count", 10); ZipEntry copy = file.getEntry("src/" + name);
CONFIG.save(); if (copy == null)
{
return;
}
input = file.getInputStream(copy);
}
catch (IOException ioex)
{
log.severe("[TotalFreedomMod]: Unable to read default configuration: " + name);
}
if (input != null)
{
FileOutputStream output = null;
try
{
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0)
{
output.write(buf, 0, length);
}
log.info("[TotalFreedomMod]: Default configuration file written: " + name);
}
catch (IOException ioex)
{
log.severe("[TotalFreedomMod]: Unable to write default configuration: " + name);
}
finally
{
try
{
if (input != null)
{
input.close();
}
}
catch (IOException ioex)
{
}
try
{
if (output != null)
{
output.close();
}
}
catch (IOException ioex)
{
}
}
}
} }
CONFIG.load();
superadmins = CONFIG.getStringList("superadmins", null);
superadmin_ips = CONFIG.getStringList("superadmin_ips", null);
allowExplosions = CONFIG.getBoolean("allow_explosions", false);
allowFirePlace = CONFIG.getBoolean("allow_fire_place", false);
allowFireSpread = CONFIG.getBoolean("allow_fire_spread", false);
allowLavaDamage = CONFIG.getBoolean("allow_lava_damage", false);
allowLavaPlace = CONFIG.getBoolean("allow_lava_place", false);
allowWaterPlace = CONFIG.getBoolean("allow_water_place", false);
autoEntityWipe = CONFIG.getBoolean("auto_wipe", false);
explosiveRadius = CONFIG.getDouble("explosiveRadius", 4.0D);
nukeMonitor = CONFIG.getBoolean("nuke_monitor", true);
nukeMonitorCountBreak = CONFIG.getInt("nuke_monitor_count", 40);
nukeMonitorRange = CONFIG.getDouble("nuke_monitor_range", 10.0D);
preprocessLogEnabled = CONFIG.getBoolean("preprocess_log", false);
freecamTriggerCount = CONFIG.getInt("freecam_trigger_count", 10);
} }
private void registerEventHandlers() private void registerEventHandlers()
@ -327,13 +385,13 @@ public class TotalFreedomMod extends JavaPlugin
this.getCommand("list").setExecutor(OverrideCommands); this.getCommand("list").setExecutor(OverrideCommands);
this.getCommand("listreal").setExecutor(OverrideCommands); this.getCommand("listreal").setExecutor(OverrideCommands);
} }
public void gotoWorld(CommandSender sender, String targetworld) public void gotoWorld(CommandSender sender, String targetworld)
{ {
if (sender instanceof Player) if (sender instanceof Player)
{ {
Player sender_p = (Player) sender; Player sender_p = (Player) sender;
if (sender_p.getWorld().getName().equalsIgnoreCase(targetworld)) if (sender_p.getWorld().getName().equalsIgnoreCase(targetworld))
{ {
sender.sendMessage(ChatColor.GRAY + "Going to main world."); sender.sendMessage(ChatColor.GRAY + "Going to main world.");
@ -356,7 +414,7 @@ public class TotalFreedomMod extends JavaPlugin
sender.sendMessage("This command may not be used from the console."); sender.sendMessage("This command may not be used from the console.");
} }
} }
public void buildHistory(Location location, int length, TFM_UserInfo playerdata) public void buildHistory(Location location, int length, TFM_UserInfo playerdata)
{ {
Block center_block = location.getBlock(); Block center_block = location.getBlock();