mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 19:24:44 +02:00
Pull changes from dev-dbman (commit f63c5e3
)
This commit is contained in:
@ -10,7 +10,6 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
@ -22,7 +21,7 @@ public class McremoveCommand implements TabExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, new PlayerProfile(args[0], false))) {
|
||||
if (UserManager.getPlayer(args[0]) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.gmail.nossr50.commands.database;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class MmoshowdbCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length != 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass();
|
||||
if (clazz != null) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", clazz.getName()));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", "sql"));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", "flatfile"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
@ -9,41 +9,130 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.database.SQLConversionTask;
|
||||
import com.gmail.nossr50.runnables.database.ConversionTask;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class MmoupdateCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!Config.getInstance().getUseMySQL()) {
|
||||
sender.sendMessage("SQL Mode is not enabled."); // TODO: Localize
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start"));
|
||||
case 1:
|
||||
String argType = args[0];
|
||||
String oldType = validateName(sender, args[0]);
|
||||
if (oldType == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String newType = getCurrentDb();
|
||||
|
||||
if (newType.equals(oldType)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Same", argType));
|
||||
return true;
|
||||
}
|
||||
|
||||
DatabaseManager oldDb;
|
||||
if (oldType == "sql") {
|
||||
oldDb = DatabaseManagerFactory.createSQLDatabaseManager();
|
||||
}
|
||||
else if (oldType == "flatfile") {
|
||||
oldDb = DatabaseManagerFactory.createFlatfileDatabaseManager();
|
||||
}
|
||||
else try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends DatabaseManager> clazz = (Class<? extends DatabaseManager>) Class.forName(oldType);
|
||||
oldDb = DatabaseManagerFactory.createCustomDatabaseManager((Class<? extends DatabaseManager>) clazz);
|
||||
|
||||
oldType = clazz.getSimpleName(); // For pretty-printing; we have the database now
|
||||
}
|
||||
catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Start", oldType, newType));
|
||||
|
||||
// Convert the online players right away, without waiting
|
||||
// first, flush out the current data
|
||||
UserManager.saveAll();
|
||||
UserManager.clearAll();
|
||||
new SQLConversionTask().runTaskLaterAsynchronously(mcMMO.p, 1);
|
||||
|
||||
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
|
||||
// Get the profile from the old database and save it in the new
|
||||
PlayerProfile profile = oldDb.loadPlayerProfile(player.getName(), false);
|
||||
if (profile.isLoaded()) {
|
||||
mcMMO.getDatabaseManager().saveUser(profile);
|
||||
}
|
||||
|
||||
// Reload from the current database via UserManager
|
||||
UserManager.addUser(player);
|
||||
}
|
||||
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.Finish"));
|
||||
// Schedule the task for all users
|
||||
new ConversionTask(oldDb, sender, oldType, newType).runTaskAsynchronously(mcMMO.p);
|
||||
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null - if type not recognized / class not found
|
||||
* empty string - if type is same as current
|
||||
* normalized string - if type is recognized
|
||||
*/
|
||||
private String validateName(CommandSender sender, String type) {
|
||||
if (type.equalsIgnoreCase("sql") || type.equalsIgnoreCase("mysql")) {
|
||||
return "sql";
|
||||
}
|
||||
|
||||
if (type.equalsIgnoreCase("flatfile") || type.equalsIgnoreCase("file")) {
|
||||
return "flatfile";
|
||||
}
|
||||
|
||||
try {
|
||||
Class<?> clazz = Class.forName(type);
|
||||
|
||||
if (!DatabaseManager.class.isAssignableFrom(clazz)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.InvalidType", type));
|
||||
return null;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
catch (Exception e) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mmoupdate.InvalidType", type));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getCurrentDb() {
|
||||
if (DatabaseManagerFactory.getCustomDatabaseManagerClass() != null) {
|
||||
return DatabaseManagerFactory.getCustomDatabaseManagerClass().getSimpleName();
|
||||
}
|
||||
|
||||
if (Config.getInstance().getUseMySQL()) {
|
||||
return "sql";
|
||||
}
|
||||
else {
|
||||
return "flatfile";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return ImmutableList.of();
|
||||
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass();
|
||||
if (clazz != null) {
|
||||
return ImmutableList.of("flatfile", "sql", clazz.getName());
|
||||
}
|
||||
return ImmutableList.of("flatfile", "sql");
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
@ -68,7 +69,7 @@ public abstract class ExperienceCommand implements TabExecutor {
|
||||
|
||||
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||
if (mcMMOPlayer == null) {
|
||||
profile = new PlayerProfile(args[0], false);
|
||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||
|
||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||
return true;
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -61,7 +60,7 @@ public class SkillresetCommand extends ExperienceCommand {
|
||||
|
||||
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||
if (mcMMOPlayer == null) {
|
||||
profile = new PlayerProfile(args[0], false);
|
||||
profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false);
|
||||
|
||||
if (CommandUtils.unloadedProfile(sender, profile)) {
|
||||
return true;
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
@ -35,7 +36,7 @@ public class InspectCommand implements TabExecutor {
|
||||
|
||||
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
|
||||
if (mcMMOPlayer == null) {
|
||||
PlayerProfile profile = new PlayerProfile(args[0], false); // Temporary Profile
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(args[0], false); // Temporary Profile
|
||||
|
||||
if (CommandUtils.inspectOffline(sender, profile, Permissions.inspectOffline(sender))) {
|
||||
return true;
|
||||
|
@ -13,7 +13,6 @@ import org.bukkit.util.StringUtil;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
@ -61,7 +60,7 @@ public class McrankCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (CommandUtils.inspectOffline(sender, new PlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
||||
else if (CommandUtils.inspectOffline(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false), Permissions.mcrankOffline(sender))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user