Part 1 of refactoring/config overhaul

This commit is contained in:
nossr50
2012-04-26 07:27:57 -07:00
parent f09b055872
commit 9606dd3501
40 changed files with 385 additions and 859 deletions

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.runnables.SQLConversionTask;
public class MmoupdateCommand implements CommandExecutor {
@ -42,7 +42,7 @@ public class MmoupdateCommand implements CommandExecutor {
* Convert FlatFile data to MySQL data.
*/
private void convertToMySQL() {
if (!LoadProperties.useMySQL) {
if (!Config.getUseMySQL()) {
return;
}

View File

@ -8,12 +8,12 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.mcLocale;
public class XprateCommand implements CommandExecutor {
private final mcMMO plugin;
private static int oldrate = LoadProperties.xpGainMultiplier;
private static int oldrate = Config.xpGainMultiplier;
public static boolean xpevent = false;
public XprateCommand (mcMMO plugin) {
@ -39,10 +39,10 @@ public class XprateCommand implements CommandExecutor {
}
xpevent = !xpevent;
LoadProperties.xpGainMultiplier = oldrate;
Config.xpGainMultiplier = oldrate;
}
else {
LoadProperties.xpGainMultiplier = oldrate;
Config.xpGainMultiplier = oldrate;
}
}
else if (m.isInt(args[0])) {
@ -56,7 +56,7 @@ public class XprateCommand implements CommandExecutor {
case 2:
if (m.isInt(args[0])) {
oldrate = LoadProperties.xpGainMultiplier;
oldrate = Config.xpGainMultiplier;
if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
xpevent = Boolean.valueOf(args[1]);
@ -65,16 +65,16 @@ public class XprateCommand implements CommandExecutor {
sender.sendMessage(usage3);
}
LoadProperties.xpGainMultiplier = m.getInt(args[0]);
Config.xpGainMultiplier = m.getInt(args[0]);
if (xpevent) {
for (Player x : plugin.getServer().getOnlinePlayers()) {
x.sendMessage(mcLocale.getString("Commands.xprate.started.0"));
x.sendMessage(mcLocale.getString("Commands.xprate.started.1", new Object[] {LoadProperties.xpGainMultiplier}));
x.sendMessage(mcLocale.getString("Commands.xprate.started.1", new Object[] {Config.xpGainMultiplier}));
}
}
else {
sender.sendMessage("The XP RATE was modified to " + LoadProperties.xpGainMultiplier); //TODO: Locale
sender.sendMessage("The XP RATE was modified to " + Config.xpGainMultiplier); //TODO: Locale
}
}
else {

View File

@ -7,7 +7,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.mcLocale;
public class McmmoCommand implements CommandExecutor {
@ -18,8 +18,8 @@ public class McmmoCommand implements CommandExecutor {
String[] mcSplit = description.split(",");
sender.sendMessage(mcSplit);
if (LoadProperties.donateMessage) {
if (LoadProperties.spoutEnabled && sender instanceof SpoutPlayer) {
if (Config.donateMessage) {
if (Config.spoutEnabled && sender instanceof SpoutPlayer) {
SpoutPlayer sPlayer = (SpoutPlayer) sender;
sPlayer.sendNotification(ChatColor.YELLOW + "[mcMMO]" + ChatColor.GOLD + " Donate!", ChatColor.GREEN + "nossr50@gmail.com", Material.DIAMOND);

View File

@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.mcLocale;
public class McremoveCommand implements CommandExecutor {
@ -27,6 +27,8 @@ public class McremoveCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String playerName;
String tablePrefix = Config.getMySQLTablePrefix();
String databaseName = Config.getMySQLDatabaseName();
String usage = ChatColor.RED + "Proper usage is /mcremove <player>"; //TODO: Needs more locale.
String success;
@ -46,35 +48,35 @@ public class McremoveCommand implements CommandExecutor {
}
/* MySQL */
if (LoadProperties.useMySQL) {
if (Config.getUseMySQL()) {
int userId = 0;
userId = mcMMO.database.getInt("SELECT id FROM " + LoadProperties.MySQLtablePrefix + "users WHERE user = '" + playerName + "'");
userId = mcMMO.database.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
if (userId > 0) {
mcMMO.database.write("DELETE FROM "
+ LoadProperties.MySQLdbName + "."
+ LoadProperties.MySQLtablePrefix + "users WHERE "
+ LoadProperties.MySQLtablePrefix + "users.id=" + userId);
+ databaseName + "."
+ tablePrefix + "users WHERE "
+ tablePrefix + "users.id=" + userId);
mcMMO.database.write("DELETE FROM "
+ LoadProperties.MySQLdbName + "."
+ LoadProperties.MySQLtablePrefix + "cooldowns WHERE "
+ LoadProperties.MySQLtablePrefix + "cooldowns.user_id=" + userId);
+ databaseName + "."
+ tablePrefix + "cooldowns WHERE "
+ tablePrefix + "cooldowns.user_id=" + userId);
mcMMO.database.write("DELETE FROM "
+ LoadProperties.MySQLdbName + "."
+ LoadProperties.MySQLtablePrefix + "huds WHERE "
+ LoadProperties.MySQLtablePrefix + "huds.user_id=" + userId);
+ databaseName + "."
+ tablePrefix + "huds WHERE "
+ tablePrefix + "huds.user_id=" + userId);
mcMMO.database.write("DELETE FROM "
+ LoadProperties.MySQLdbName + "."
+ LoadProperties.MySQLtablePrefix + "skills WHERE "
+ LoadProperties.MySQLtablePrefix + "skills.user_id=" + userId);
+ databaseName + "."
+ tablePrefix + "skills WHERE "
+ tablePrefix + "skills.user_id=" + userId);
mcMMO.database.write("DELETE FROM "
+ LoadProperties.MySQLdbName + "."
+ LoadProperties.MySQLtablePrefix + "experience WHERE "
+ LoadProperties.MySQLtablePrefix + "experience.user_id=" + userId);
+ databaseName + "."
+ tablePrefix + "experience WHERE "
+ tablePrefix + "experience.user_id=" + userId);
sender.sendMessage(success);

View File

@ -10,7 +10,7 @@ import org.bukkit.command.CommandSender;
import com.gmail.nossr50.Leaderboard;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.Skills;
@ -19,7 +19,8 @@ public class MctopCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
String usage = ChatColor.RED + "Proper usage is /mctop [skill] [page]"; //TODO: Needs more locale.
if (!LoadProperties.useMySQL) {
if (!Config.getUseMySQL()) {
switch (args.length) {
case 0:
@ -131,7 +132,8 @@ public class MctopCommand implements CommandExecutor {
}
private void sqlDisplay(int page, String query, CommandSender sender) {
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + query + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC ");
String tablePrefix = Config.getMySQLTablePrefix();
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC ");
if (query == "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing") {
sender.sendMessage(mcLocale.getString("Commands.PowerLevel.Leaderboard"));
@ -141,11 +143,11 @@ public class MctopCommand implements CommandExecutor {
}
for (int i = (page * 10) - 9; i <= (page * 10); i++) {
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null) {
break;
}
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
sender.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
}
}

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent;
import com.gmail.nossr50.locale.mcLocale;
@ -44,8 +44,8 @@ public class PtpCommand implements CommandExecutor {
return true;
}
if (PP.getRecentlyHurt() + (LoadProperties.ptpCommandCooldown * 1000) > System.currentTimeMillis()) {
player.sendMessage(mcLocale.getString("Party.Teleport.Hurt", new Object[] { LoadProperties.ptpCommandCooldown }));
if (PP.getRecentlyHurt() + (Config.ptpCommandCooldown * 1000) > System.currentTimeMillis()) {
player.sendMessage(mcLocale.getString("Party.Teleport.Hurt", new Object[] { Config.ptpCommandCooldown }));
return true;
}

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
@ -45,7 +45,7 @@ public class RepairCommand implements CommandExecutor {
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Repair.Effect.0"), mcLocale.getString("Repair.Effect.1") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Repair.Effect.2"), mcLocale.getString("Repair.Effect.3") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Repair.Effect.4"), mcLocale.getString("Repair.Effect.5") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Repair.Effect.6", new Object[] { LoadProperties.repairDiamondLevel }), mcLocale.getString("Repair.Effect.7") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Repair.Effect.6", new Object[] { Config.repairDiamondLevel }), mcLocale.getString("Repair.Effect.7") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Repair.Effect.8"), mcLocale.getString("Repair.Effect.9") }));
player.sendMessage(mcLocale.getString("Skills.Header", new Object[] { mcLocale.getString("Commands.Stats.Self") }));

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
@ -46,8 +46,8 @@ public class TamingCommand implements CommandExecutor {
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Taming.Effect.10"), mcLocale.getString("Taming.Effect.11") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Taming.Effect.12"), mcLocale.getString("Taming.Effect.13") }));
player.sendMessage(mcLocale.getString("Effects.Template", new Object[] { mcLocale.getString("Taming.Effect.16"), mcLocale.getString("Taming.Effect.17") }));
player.sendMessage(mcLocale.getString("Taming.Effect.14", new Object[] { LoadProperties.fishConsumedByCOTW }));
player.sendMessage(mcLocale.getString("Taming.Effect.15", new Object[] { LoadProperties.bonesConsumedByCOTW }));
player.sendMessage(mcLocale.getString("Taming.Effect.14", new Object[] { Config.fishConsumedByCOTW }));
player.sendMessage(mcLocale.getString("Taming.Effect.15", new Object[] { Config.bonesConsumedByCOTW }));
player.sendMessage(mcLocale.getString("Skills.Header", new Object[] { mcLocale.getString("Commands.Stats.Self") }));

View File

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.HUDType;
import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.PlayerProfile;
@ -32,7 +32,7 @@ public class MchudCommand implements CommandExecutor {
return true;
}
if (!LoadProperties.spoutEnabled || !LoadProperties.xpbar) {
if (!Config.spoutEnabled || !Config.xpbar) {
sender.sendMessage(mcLocale.getString("Commands.Disabled"));
return true;
}

View File

@ -10,7 +10,7 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
@ -26,7 +26,7 @@ public class XplockCommand implements CommandExecutor {
return true;
}
if (!LoadProperties.spoutEnabled || !LoadProperties.xpbar || !LoadProperties.xplockEnable) {
if (!Config.spoutEnabled || !Config.xpbar || !Config.xplockEnable) {
sender.sendMessage(mcLocale.getString("Commands.Disabled"));
return true;
}