mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Use a single manager to handle our databases.
This commit is contained in:
@ -6,9 +6,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.FlatfileDatabaseManager;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
|
||||
public class McrankCommandAsyncTask extends BukkitRunnable {
|
||||
private final String playerName;
|
||||
@ -21,8 +18,9 @@ public class McrankCommandAsyncTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Map<String, Integer> skills = Config.getInstance().getUseMySQL() ? SQLDatabaseManager.readSQLRank(playerName) : FlatfileDatabaseManager.getPlayerRanks(playerName);
|
||||
Map<String, Integer> skills = mcMMO.getDatabaseManager().readRank(playerName);
|
||||
|
||||
new McrankCommandDisplayTask(skills, sender, playerName).runTaskLater(mcMMO.p, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,31 +1,28 @@
|
||||
package com.gmail.nossr50.runnables.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
|
||||
public class MctopCommandAsyncTask extends BukkitRunnable {
|
||||
private CommandSender sender;
|
||||
private String query;
|
||||
private String skill;
|
||||
private int page;
|
||||
|
||||
public MctopCommandAsyncTask(int page, String query, CommandSender sender) {
|
||||
public MctopCommandAsyncTask(int page, String skill, CommandSender sender) {
|
||||
this.page = page;
|
||||
this.query = query.equalsIgnoreCase("ALL") ? "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing" : query;
|
||||
this.skill = skill;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
final Collection<ArrayList<String>> userStats = SQLDatabaseManager.read("SELECT " + query + ", user, NOW() FROM " + tablePrefix + "users JOIN " + tablePrefix + "skills ON (user_id = id) WHERE " + query + " > 0 ORDER BY " + query + " DESC, user LIMIT " + ((page * 10) - 10) + ",10").values();
|
||||
final List<PlayerStat> userStats = mcMMO.getDatabaseManager().readLeaderboard(skill, page, 10);
|
||||
|
||||
new MctopCommandDisplayTask(userStats, page, tablePrefix, sender).runTaskLater(mcMMO.p, 1);
|
||||
new MctopCommandDisplayTask(userStats, page, skill, sender).runTaskLater(mcMMO.p, 1);
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,44 @@
|
||||
package com.gmail.nossr50.runnables.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.datatypes.database.PlayerStat;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class MctopCommandDisplayTask extends BukkitRunnable {
|
||||
private Collection<ArrayList<String>> userStats;
|
||||
private List<PlayerStat> userStats;
|
||||
private CommandSender sender;
|
||||
private String query;
|
||||
private String skill;
|
||||
private int page;
|
||||
|
||||
public MctopCommandDisplayTask(Collection<ArrayList<String>> userStats, int page, String query, CommandSender sender) {
|
||||
public MctopCommandDisplayTask(List<PlayerStat> userStats, int page, String skill, CommandSender sender) {
|
||||
this.userStats = userStats;
|
||||
this.page = page;
|
||||
this.query = query;
|
||||
this.skill = skill;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (query.equalsIgnoreCase("taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing")) {
|
||||
if (skill.equalsIgnoreCase("all")) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(query)));
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.Skill.Leaderboard", StringUtils.getCapitalized(skill)));
|
||||
}
|
||||
|
||||
int place = (page * 10) - 9;
|
||||
|
||||
for (ArrayList<String> stat : userStats) {
|
||||
for (PlayerStat stat : userStats) {
|
||||
String digit = (place < 10) ? "0" : "" + String.valueOf(place);
|
||||
|
||||
// Format: 1. Playername - skill value
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.get(1) + " - " + ChatColor.WHITE + stat.get(0));
|
||||
sender.sendMessage(digit + ". " + ChatColor.GREEN + stat.name + " - " + ChatColor.WHITE + stat.statVal);
|
||||
place++;
|
||||
}
|
||||
|
||||
|
@ -6,270 +6,28 @@ import java.io.FileReader;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
|
||||
public class SQLConversionTask extends BukkitRunnable {
|
||||
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String location = mcMMO.getUsersFilePath();
|
||||
|
||||
try {
|
||||
FileReader file = new FileReader(location);
|
||||
BufferedReader in = new BufferedReader(file);
|
||||
BufferedReader in = new BufferedReader(new FileReader(location));
|
||||
String line = "";
|
||||
String playerName = null;
|
||||
String mining = null;
|
||||
String woodcutting = null;
|
||||
String repair = null;
|
||||
String unarmed = null;
|
||||
String herbalism = null;
|
||||
String excavation = null;
|
||||
String archery = null;
|
||||
String swords = null;
|
||||
String axes = null;
|
||||
String acrobatics = null;
|
||||
String taming = null;
|
||||
String fishing = null;
|
||||
String miningXP = null;
|
||||
String woodCuttingXP = null;
|
||||
String repairXP = null;
|
||||
String unarmedXP = null;
|
||||
String herbalismXP = null;
|
||||
String excavationXP = null;
|
||||
String archeryXP = null;
|
||||
String swordsXP = null;
|
||||
String axesXP = null;
|
||||
String acrobaticsXP = null;
|
||||
String tamingXP = null;
|
||||
String fishingXP = null;
|
||||
int id = 0;
|
||||
int theCount = 0;
|
||||
int converted = 0;
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
||||
// Find if the line contains the player we want.
|
||||
String[] character = line.split(":");
|
||||
playerName = character[0];
|
||||
|
||||
// Check for things we don't want put in the DB
|
||||
if (playerName == null || playerName.equalsIgnoreCase("null") || playerName.equalsIgnoreCase("#Storage place for user information")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (character.length > 1) {
|
||||
mining = character[1];
|
||||
}
|
||||
|
||||
if (character.length > 4) {
|
||||
miningXP = character[4];
|
||||
}
|
||||
|
||||
if (character.length > 5) {
|
||||
woodcutting = character[5];
|
||||
}
|
||||
|
||||
if (character.length > 6) {
|
||||
woodCuttingXP = character[6];
|
||||
}
|
||||
|
||||
if (character.length > 7) {
|
||||
repair = character[7];
|
||||
}
|
||||
|
||||
if (character.length > 8) {
|
||||
unarmed = character[8];
|
||||
}
|
||||
|
||||
if (character.length > 9) {
|
||||
herbalism = character[9];
|
||||
}
|
||||
|
||||
if (character.length > 10) {
|
||||
excavation = character[10];
|
||||
}
|
||||
|
||||
if (character.length > 11) {
|
||||
archery = character[11];
|
||||
}
|
||||
|
||||
if (character.length > 12) {
|
||||
swords = character[12];
|
||||
}
|
||||
|
||||
if (character.length > 13) {
|
||||
axes = character[13];
|
||||
}
|
||||
|
||||
if (character.length > 14) {
|
||||
acrobatics = character[14];
|
||||
}
|
||||
|
||||
if (character.length > 15) {
|
||||
repairXP = character[15];
|
||||
}
|
||||
|
||||
if (character.length > 16) {
|
||||
unarmedXP = character[16];
|
||||
}
|
||||
|
||||
if (character.length > 17) {
|
||||
herbalismXP = character[17];
|
||||
}
|
||||
|
||||
if (character.length > 18) {
|
||||
excavationXP = character[18];
|
||||
}
|
||||
|
||||
if (character.length > 19) {
|
||||
archeryXP = character[19];
|
||||
}
|
||||
|
||||
if (character.length > 20) {
|
||||
swordsXP = character[20];
|
||||
}
|
||||
|
||||
if (character.length > 21) {
|
||||
axesXP = character[21];
|
||||
}
|
||||
|
||||
if (character.length > 22) {
|
||||
acrobaticsXP = character[22];
|
||||
}
|
||||
|
||||
if (character.length > 24) {
|
||||
taming = character[24];
|
||||
}
|
||||
|
||||
if (character.length > 25) {
|
||||
tamingXP = character[25];
|
||||
}
|
||||
|
||||
if (character.length > 34) {
|
||||
fishing = character[34];
|
||||
}
|
||||
|
||||
if (character.length > 35) {
|
||||
fishingXP = character[35];
|
||||
}
|
||||
|
||||
// Check to see if the user is in the DB
|
||||
id = SQLDatabaseManager.getInt("SELECT id FROM "
|
||||
+ tablePrefix
|
||||
+ "users WHERE user = '" + playerName + "'");
|
||||
|
||||
if (id > 0) {
|
||||
theCount++;
|
||||
|
||||
// Update the skill values
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "users SET lastlogin = " + 0
|
||||
+ " WHERE id = " + id);
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "skills SET "
|
||||
+ " taming = taming+" + StringUtils.getInt(taming)
|
||||
+ ", mining = mining+" + StringUtils.getInt(mining)
|
||||
+ ", repair = repair+" + StringUtils.getInt(repair)
|
||||
+ ", woodcutting = woodcutting+" + StringUtils.getInt(woodcutting)
|
||||
+ ", unarmed = unarmed+" + StringUtils.getInt(unarmed)
|
||||
+ ", herbalism = herbalism+" + StringUtils.getInt(herbalism)
|
||||
+ ", excavation = excavation+" + StringUtils.getInt(excavation)
|
||||
+ ", archery = archery+" + StringUtils.getInt(archery)
|
||||
+ ", swords = swords+" + StringUtils.getInt(swords)
|
||||
+ ", axes = axes+" + StringUtils.getInt(axes)
|
||||
+ ", acrobatics = acrobatics+" + StringUtils.getInt(acrobatics)
|
||||
+ ", fishing = fishing+" + StringUtils.getInt(fishing)
|
||||
+ " WHERE user_id = " + id);
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "experience SET "
|
||||
+ " taming = " + StringUtils.getInt(tamingXP)
|
||||
+ ", mining = " + StringUtils.getInt(miningXP)
|
||||
+ ", repair = " + StringUtils.getInt(repairXP)
|
||||
+ ", woodcutting = " + StringUtils.getInt(woodCuttingXP)
|
||||
+ ", unarmed = " + StringUtils.getInt(unarmedXP)
|
||||
+ ", herbalism = " + StringUtils.getInt(herbalismXP)
|
||||
+ ", excavation = " + StringUtils.getInt(excavationXP)
|
||||
+ ", archery = " + StringUtils.getInt(archeryXP)
|
||||
+ ", swords = " + StringUtils.getInt(swordsXP)
|
||||
+ ", axes = " + StringUtils.getInt(axesXP)
|
||||
+ ", acrobatics = " + StringUtils.getInt(acrobaticsXP)
|
||||
+ ", fishing = " + StringUtils.getInt(fishingXP)
|
||||
+ " WHERE user_id = " + id);
|
||||
}
|
||||
else {
|
||||
theCount++;
|
||||
|
||||
// Create the user in the DB
|
||||
SQLDatabaseManager.write("INSERT INTO "
|
||||
+ tablePrefix
|
||||
+ "users (user, lastlogin) VALUES ('"
|
||||
+ playerName + "',"
|
||||
+ System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR + ")");
|
||||
id = SQLDatabaseManager.getInt("SELECT id FROM "
|
||||
+ tablePrefix
|
||||
+ "users WHERE user = '"
|
||||
+ playerName + "'");
|
||||
SQLDatabaseManager.write("INSERT INTO "
|
||||
+ tablePrefix
|
||||
+ "skills (user_id) VALUES (" + id + ")");
|
||||
SQLDatabaseManager.write("INSERT INTO "
|
||||
+ tablePrefix
|
||||
+ "experience (user_id) VALUES (" + id
|
||||
+ ")");
|
||||
// Update the skill values
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "users SET lastlogin = " + 0
|
||||
+ " WHERE id = " + id);
|
||||
/*
|
||||
Database.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "users SET party = '" + party
|
||||
+ "' WHERE id = " + id);
|
||||
*/
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "skills SET "
|
||||
+ " taming = taming+" + StringUtils.getInt(taming)
|
||||
+ ", mining = mining+" + StringUtils.getInt(mining)
|
||||
+ ", repair = repair+" + StringUtils.getInt(repair)
|
||||
+ ", woodcutting = woodcutting+" + StringUtils.getInt(woodcutting)
|
||||
+ ", unarmed = unarmed+" + StringUtils.getInt(unarmed)
|
||||
+ ", herbalism = herbalism+" + StringUtils.getInt(herbalism)
|
||||
+ ", excavation = excavation+" + StringUtils.getInt(excavation)
|
||||
+ ", archery = archery+" + StringUtils.getInt(archery)
|
||||
+ ", swords = swords+" + StringUtils.getInt(swords)
|
||||
+ ", axes = axes+" + StringUtils.getInt(axes)
|
||||
+ ", acrobatics = acrobatics+" + StringUtils.getInt(acrobatics)
|
||||
+ ", fishing = fishing+" + StringUtils.getInt(fishing)
|
||||
+ " WHERE user_id = " + id);
|
||||
SQLDatabaseManager.write("UPDATE "
|
||||
+ tablePrefix
|
||||
+ "experience SET "
|
||||
+ " taming = " + StringUtils.getInt(tamingXP)
|
||||
+ ", mining = " + StringUtils.getInt(miningXP)
|
||||
+ ", repair = " + StringUtils.getInt(repairXP)
|
||||
+ ", woodcutting = " + StringUtils.getInt(woodCuttingXP)
|
||||
+ ", unarmed = " + StringUtils.getInt(unarmedXP)
|
||||
+ ", herbalism = " + StringUtils.getInt(herbalismXP)
|
||||
+ ", excavation = " + StringUtils.getInt(excavationXP)
|
||||
+ ", archery = " + StringUtils.getInt(archeryXP)
|
||||
+ ", swords = " + StringUtils.getInt(swordsXP)
|
||||
+ ", axes = " + StringUtils.getInt(axesXP)
|
||||
+ ", acrobatics = " + StringUtils.getInt(acrobaticsXP)
|
||||
+ ", fishing = " + StringUtils.getInt(fishingXP)
|
||||
+ " WHERE user_id = " + id);
|
||||
String[] playerData = line.split(":");
|
||||
if (mcMMO.getDatabaseManager().convert(playerData)) {
|
||||
converted++;
|
||||
}
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("[mcMMO] MySQL Updated from users file, " + theCount + " items added/updated to MySQL DB");
|
||||
mcMMO.p.getLogger().info("MySQL Updated from users file, " + converted + " items added/updated to MySQL DB");
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -10,7 +10,7 @@ import com.gmail.nossr50.util.player.UserManager;
|
||||
public class SQLReconnectTask extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
if (SQLDatabaseManager.checkConnected()) {
|
||||
if (((SQLDatabaseManager) mcMMO.getDatabaseManager()).checkConnected()) {
|
||||
UserManager.saveAll(); // Save all profiles
|
||||
UserManager.clearAll(); // Clear the profiles
|
||||
|
||||
|
Reference in New Issue
Block a user