Config migration, stage 1

This commit is contained in:
Steven Lawson 2013-08-18 14:52:46 -04:00
parent 64b1e568b3
commit 2827ca98a7
18 changed files with 65 additions and 110 deletions

View File

@ -1,8 +1,8 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -21,13 +21,13 @@ public class Command_adminmode extends TFM_Command
if (args[0].equalsIgnoreCase("off"))
{
TotalFreedomMod.adminOnlyMode = false;
TFM_ConfigEntry.ADMIN_ONLY_MODE.setBoolean(false);
TFM_Util.adminAction(sender.getName(), "Opening the server to all players.", true);
return true;
}
else if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.adminOnlyMode = true;
TFM_ConfigEntry.ADMIN_ONLY_MODE.setBoolean(true);
TFM_Util.adminAction(sender.getName(), "Closing the server to non-superadmins.", true);
for (Player player : server.getOnlinePlayers())
{

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -18,7 +18,7 @@ public class Command_droptoggle extends TFM_Command
return false;
}
TFM_Util.adminAction(sender.getName(),
((TotalFreedomMod.autoEntityWipe = !args[0].equalsIgnoreCase("off")) ? "Enabled" : "Disabled")
(TFM_ConfigEntry.AUTO_ENTITY_WIPE.setBoolean(!args[0].equalsIgnoreCase("off")) ? "Enabled" : "Disabled")
+ " automatic entity wiping.", false);
return true;
}

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
@ -33,12 +34,12 @@ public class Command_explosives extends TFM_Command
if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.allowExplosions = true;
TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(true);
playerMsg("Explosives are now enabled, radius set to " + TotalFreedomMod.explosiveRadius + " blocks.");
}
else
{
TotalFreedomMod.allowExplosions = false;
TFM_ConfigEntry.ALLOW_EXPLOSIONS.setBoolean(false);
playerMsg("Explosives are now disabled.");
}

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -19,12 +19,12 @@ public class Command_fireplace extends TFM_Command
if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.allowFirePlace = true;
TFM_ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(true);
playerMsg("Fire placement is now enabled.");
}
else
{
TotalFreedomMod.allowFirePlace = false;
TFM_ConfigEntry.ALLOW_FIRE_PLACE.setBoolean(false);
playerMsg("Fire placement is now disabled.");
}

View File

@ -1,7 +1,7 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -18,9 +18,13 @@ public class Command_firespread extends TFM_Command
return false;
}
playerMsg("Fire spread is now " + ((TotalFreedomMod.allowFireSpread = !args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
boolean fireSpread = !args[0].equalsIgnoreCase("off");
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TotalFreedomMod.allowFireSpread);
TFM_ConfigEntry.ALLOW_FIRE_SPREAD.setBoolean(fireSpread);
playerMsg("Fire spread is now " + (fireSpread ? "enabled" : "disabled") + ".");
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, fireSpread);
return true;
}

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -17,16 +17,7 @@ public class Command_fluidspread extends TFM_Command
return false;
}
if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.allowFliudSpread = true;
playerMsg("Lava and water spread is now enabled.");
}
else
{
TotalFreedomMod.allowFliudSpread = false;
playerMsg("Lava and water spread is now disabled.");
}
playerMsg("Lava and water spread is now " + (TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
return true;
}

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_LandmineData;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor;
@ -21,7 +22,7 @@ public class Command_landmine extends TFM_Command
{
playerMsg("The landmine is currently disabled.", ChatColor.GREEN);
}
else if (!TotalFreedomMod.allowExplosions)
else if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
playerMsg("Explosions are currently disabled.", ChatColor.GREEN);
}

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -17,16 +17,7 @@ public class Command_lavadmg extends TFM_Command
return false;
}
if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.allowLavaDamage = true;
playerMsg("Lava damage is now enabled.");
}
else
{
TotalFreedomMod.allowLavaDamage = false;
playerMsg("Lava damage is now disabled.");
}
playerMsg("Lava damage is now " + (TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
return true;
}

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -17,16 +17,7 @@ public class Command_lavaplace extends TFM_Command
return false;
}
if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.allowLavaPlace = true;
playerMsg("Lava placement is now enabled.");
}
else
{
TotalFreedomMod.allowLavaPlace = false;
playerMsg("Lava placement is now disabled.");
}
playerMsg("Lava placement is now " + (TFM_ConfigEntry.ALLOW_LAVA_PLACE.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
return true;
}

View File

@ -1,6 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -12,22 +12,12 @@ public class Command_waterplace extends TFM_Command
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
if (args[0].equalsIgnoreCase("on"))
{
TotalFreedomMod.allowWaterPlace = true;
playerMsg("Water placement is now enabled.");
}
else
{
TotalFreedomMod.allowWaterPlace = false;
playerMsg("Water placement is now disabled.");
}
playerMsg("Water placement is now " + (TFM_ConfigEntry.ALLOW_WATER_PLACE.setBoolean(!args[0].equalsIgnoreCase("off")) ? "enabled" : "disabled") + ".");
return true;
}

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Heartbeat;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
@ -23,7 +24,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBurn(BlockBurnEvent event)
{
if (!TotalFreedomMod.allowFireSpread)
if (!TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean())
{
event.setCancelled(true);
}
@ -32,7 +33,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onBlockIgnite(BlockIgniteEvent event)
{
if (!TotalFreedomMod.allowFirePlace)
if (!TFM_ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
{
event.setCancelled(true);
}
@ -185,7 +186,7 @@ public class TFM_BlockListener implements Listener
case LAVA:
case STATIONARY_LAVA:
{
if (TotalFreedomMod.allowLavaPlace)
if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
{
TFM_Log.info(String.format("%s placed lava @ %s", player.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
@ -203,7 +204,7 @@ public class TFM_BlockListener implements Listener
case WATER:
case STATIONARY_WATER:
{
if (TotalFreedomMod.allowWaterPlace)
if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
{
TFM_Log.info(String.format("%s placed water @ %s", player.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
@ -220,7 +221,7 @@ public class TFM_BlockListener implements Listener
}
case FIRE:
{
if (TotalFreedomMod.allowFirePlace)
if (TFM_ConfigEntry.ALLOW_FIRE_PLACE.getBoolean())
{
TFM_Log.info(String.format("%s placed fire @ %s", player.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
@ -237,7 +238,7 @@ public class TFM_BlockListener implements Listener
}
case TNT:
{
if (TotalFreedomMod.allowExplosions)
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
TFM_Log.info(String.format("%s placed TNT @ %s", player.getName(), TFM_Util.formatLocation(event.getBlock().getLocation())));
@ -264,7 +265,7 @@ public class TFM_BlockListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onBlockFromTo(BlockFromToEvent event)
{
if (!TotalFreedomMod.allowFliudSpread)
if (!TFM_ConfigEntry.ALLOW_FLIUD_SPREAD.getBoolean())
{
event.setCancelled(true);
}

View File

@ -1,5 +1,6 @@
package me.StevenLawson.TotalFreedomMod.Listener;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
@ -12,7 +13,7 @@ public class TFM_EntityListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onEntityExplode(EntityExplodeEvent event)
{
if (!TotalFreedomMod.allowExplosions)
if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
event.setCancelled(true);
return;
@ -24,7 +25,7 @@ public class TFM_EntityListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onExplosionPrime(ExplosionPrimeEvent event)
{
if (!TotalFreedomMod.allowExplosions)
if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
event.setCancelled(true);
return;
@ -36,7 +37,7 @@ public class TFM_EntityListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCombust(EntityCombustEvent event)
{
if (!TotalFreedomMod.allowExplosions)
if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
event.setCancelled(true);
}
@ -49,7 +50,7 @@ public class TFM_EntityListener implements Listener
{
case LAVA:
{
if (!TotalFreedomMod.allowLavaDamage)
if (!TFM_ConfigEntry.ALLOW_LAVA_DAMAGE.getBoolean())
{
event.setCancelled(true);
return;
@ -144,7 +145,7 @@ public class TFM_EntityListener implements Listener
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event)
{
if (TotalFreedomMod.autoEntityWipe)
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
{
event.setDroppedExp(0);
}
@ -153,7 +154,7 @@ public class TFM_EntityListener implements Listener
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHit(ProjectileHitEvent event)
{
if (TotalFreedomMod.allowExplosions)
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
Projectile entity = event.getEntity();
if (event.getEntityType() == EntityType.ARROW && entity.getShooter() instanceof Player)

View File

@ -46,7 +46,7 @@ public class TFM_PlayerListener implements Listener
{
case WATER_BUCKET:
{
if (!TotalFreedomMod.allowWaterPlace)
if (!TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean())
{
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
@ -56,7 +56,7 @@ public class TFM_PlayerListener implements Listener
}
case LAVA_BUCKET:
{
if (!TotalFreedomMod.allowLavaPlace)
if (!TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean())
{
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
@ -66,7 +66,7 @@ public class TFM_PlayerListener implements Listener
}
case EXPLOSIVE_MINECART:
{
if (!TotalFreedomMod.allowTntMinecarts)
if (!TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean())
{
player.getInventory().clear(player.getInventory().getHeldItemSlot());
player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
@ -118,7 +118,7 @@ public class TFM_PlayerListener implements Listener
}
case BLAZE_ROD:
{
if (TotalFreedomMod.allowExplosions)
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
if (TFM_SuperadminList.isSeniorAdmin(player, true))
{
@ -150,7 +150,7 @@ public class TFM_PlayerListener implements Listener
}
case CARROT:
{
if (TotalFreedomMod.allowExplosions)
if (TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
if (TFM_SuperadminList.isSeniorAdmin(player, true))
{
@ -341,7 +341,7 @@ public class TFM_PlayerListener implements Listener
TFM_Jumppads.getInstance().PlayerMoveEvent(event);
}
if (TotalFreedomMod.landminesEnabled && TotalFreedomMod.allowExplosions)
if (TotalFreedomMod.landminesEnabled && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())
{
Iterator<TFM_LandmineData> landmines = TFM_LandmineData.landmines.iterator();
while (landmines.hasNext())
@ -571,7 +571,7 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerDropItem(PlayerDropItemEvent event)
{
if (TotalFreedomMod.autoEntityWipe)
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
{
if (event.getPlayer().getWorld().getEntities().size() > 750)
{
@ -661,7 +661,7 @@ public class TFM_PlayerListener implements Listener
}
}
if (TotalFreedomMod.adminOnlyMode)
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
new BukkitRunnable()
{

View File

@ -4,10 +4,10 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlockerNew;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
@ -88,7 +88,7 @@ public class TFM_ServerListener implements Listener
{
event.setMotd(ChatColor.RED + "You are banned.");
}
else if (TotalFreedomMod.adminOnlyMode)
else if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
event.setMotd(ChatColor.RED + "Server is closed.");
}

View File

@ -75,9 +75,10 @@ public enum TFM_ConfigEntry
return TFM_Config.getInstance().getString(this);
}
public void setString(String value)
public String setString(String value)
{
TFM_Config.getInstance().setString(this, value);
return value;
}
public Double getDouble()
@ -85,9 +86,10 @@ public enum TFM_ConfigEntry
return TFM_Config.getInstance().getDouble(this);
}
public void setDouble(Double value)
public Double setDouble(Double value)
{
TFM_Config.getInstance().setDouble(this, value);
return value;
}
public Boolean getBoolean()
@ -95,9 +97,10 @@ public enum TFM_ConfigEntry
return TFM_Config.getInstance().getBoolean(this);
}
public void setBoolean(Boolean value)
public Boolean setBoolean(Boolean value)
{
TFM_Config.getInstance().setBoolean(this, value);
return value;
}
public Integer getInteger()
@ -105,9 +108,10 @@ public enum TFM_ConfigEntry
return TFM_Config.getInstance().getInteger(this);
}
public void setInteger(Integer value)
public Integer setInteger(Integer value)
{
TFM_Config.getInstance().setInteger(this, value);
return value;
}
public List getList(TFM_ConfigEntry entry)

View File

@ -35,9 +35,9 @@ public class TFM_Heartbeat extends BukkitRunnable
playerdata.resetBlockPlaceCount();
}
if (TotalFreedomMod.autoEntityWipe)
if (TFM_ConfigEntry.AUTO_ENTITY_WIPE.getBoolean())
{
TFM_Util.TFM_EntityWiper.wipeEntities(!TotalFreedomMod.allowExplosions, false);
TFM_Util.TFM_EntityWiper.wipeEntities(!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean(), false);
}
if (TotalFreedomMod.disableWeather)

View File

@ -247,7 +247,7 @@ public class TFM_ServerInterface
return;
}
if (TotalFreedomMod.adminOnlyMode)
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())
{
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server is temporarily open to admins only.");
return;

View File

@ -97,7 +97,7 @@ public class TotalFreedomMod extends JavaPlugin
// Initialize game rules
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_DAYLIGHT_CYCLE, !disableNight, false);
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, allowFireSpread, false);
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_FIRE_TICK, TFM_ConfigEntry.ALLOW_FIRE_SPREAD.getBoolean(), false);
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_LOOT, false, false);
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_MOB_SPAWNING, !mobLimiterEnabled, false);
TFM_GameRuleHandler.setGameRule(TFM_GameRuleHandler.TFM_GameRule.DO_TILE_DROPS, false, false);
@ -230,26 +230,6 @@ public class TotalFreedomMod extends JavaPlugin
}
//
@Deprecated
public static boolean adminOnlyMode = false;
@Deprecated
public static boolean allowExplosions = false;
@Deprecated
public static boolean allowFirePlace = false;
@Deprecated
public static boolean allowFireSpread = false;
@Deprecated
public static boolean allowFliudSpread = false;
@Deprecated
public static boolean allowLavaDamage = false;
@Deprecated
public static boolean allowLavaPlace = false;
@Deprecated
public static boolean allowTntMinecarts = false;
@Deprecated
public static boolean allowWaterPlace = false;
@Deprecated
public static boolean autoEntityWipe = true;
@Deprecated
public static boolean autoProtectSpawnpoints = true;
@Deprecated
public static boolean disableNight = true;