mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-02-02 11:21:22 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0121c5d106
@ -374,9 +374,8 @@ public class MMOCore extends JavaPlugin {
|
|||||||
}.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave);
|
}.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void disable() {
|
public void onDisable() {
|
||||||
|
|
||||||
// Save player data
|
// Save player data
|
||||||
for (PlayerData data : PlayerData.getAll())
|
for (PlayerData data : PlayerData.getAll())
|
||||||
if (data.isFullyLoaded()) {
|
if (data.isFullyLoaded()) {
|
||||||
|
@ -514,9 +514,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
|||||||
|
|
||||||
public String toJson() {
|
public String toJson() {
|
||||||
|
|
||||||
//We create the JSON correspondign to player Data
|
//We create the JSON corresponding to player Data
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, getUniqueId());
|
|
||||||
MMOCore.sqlDebug("Saving data for: '" + getUniqueId() + "'...");
|
MMOCore.sqlDebug("Saving data for: '" + getUniqueId() + "'...");
|
||||||
|
|
||||||
jsonObject.addProperty("class_points", getClassPoints());
|
jsonObject.addProperty("class_points", getClassPoints());
|
||||||
|
@ -6,6 +6,7 @@ import net.Indyuce.mmocore.MMOCore;
|
|||||||
import net.Indyuce.mmocore.command.rpg.CoinsCommandTreeNode;
|
import net.Indyuce.mmocore.command.rpg.CoinsCommandTreeNode;
|
||||||
import net.Indyuce.mmocore.command.rpg.NoteCommandTreeNode;
|
import net.Indyuce.mmocore.command.rpg.NoteCommandTreeNode;
|
||||||
import net.Indyuce.mmocore.command.rpg.ReloadCommandTreeNode;
|
import net.Indyuce.mmocore.command.rpg.ReloadCommandTreeNode;
|
||||||
|
import net.Indyuce.mmocore.command.rpg.TransferDataTreeNode;
|
||||||
import net.Indyuce.mmocore.command.rpg.admin.AdminCommandTreeNode;
|
import net.Indyuce.mmocore.command.rpg.admin.AdminCommandTreeNode;
|
||||||
import net.Indyuce.mmocore.command.rpg.booster.BoosterCommandTreeNode;
|
import net.Indyuce.mmocore.command.rpg.booster.BoosterCommandTreeNode;
|
||||||
import net.Indyuce.mmocore.command.rpg.debug.DebugCommandTreeNode;
|
import net.Indyuce.mmocore.command.rpg.debug.DebugCommandTreeNode;
|
||||||
@ -26,6 +27,7 @@ public class MMOCoreCommandTreeRoot extends CommandTreeRoot implements CommandEx
|
|||||||
super("mmocore", "mmocore.admin");
|
super("mmocore", "mmocore.admin");
|
||||||
|
|
||||||
addChild(new ReloadCommandTreeNode(this));
|
addChild(new ReloadCommandTreeNode(this));
|
||||||
|
addChild(new TransferDataTreeNode(this));
|
||||||
addChild(new CoinsCommandTreeNode(this));
|
addChild(new CoinsCommandTreeNode(this));
|
||||||
addChild(new NoteCommandTreeNode(this));
|
addChild(new NoteCommandTreeNode(this));
|
||||||
addChild(new AdminCommandTreeNode(this));
|
addChild(new AdminCommandTreeNode(this));
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package net.Indyuce.mmocore.command.rpg;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.command.api.CommandTreeNode;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import net.Indyuce.mmocore.guild.provided.Guild;
|
||||||
|
import net.Indyuce.mmocore.manager.data.DataProvider;
|
||||||
|
import net.Indyuce.mmocore.manager.data.mysql.MySQLDataProvider;
|
||||||
|
import net.Indyuce.mmocore.manager.data.yaml.YAMLDataProvider;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This command allows to transfer data from your actual datatype (yaml or sql) to the other one to make a change
|
||||||
|
* in the data storage type.
|
||||||
|
*/
|
||||||
|
public class TransferDataTreeNode extends CommandTreeNode {
|
||||||
|
|
||||||
|
|
||||||
|
public TransferDataTreeNode(CommandTreeNode parent) {
|
||||||
|
super(parent, "transferdata");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult execute(CommandSender commandSender, String[] strings) {
|
||||||
|
DataProvider provider=null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (MMOCore.plugin.dataProvider instanceof YAMLDataProvider) {
|
||||||
|
provider = new MySQLDataProvider(MMOCore.plugin.getConfig());
|
||||||
|
((MySQLDataProvider) provider).load();
|
||||||
|
} else {
|
||||||
|
provider = new YAMLDataProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save player data
|
||||||
|
for (PlayerData data : PlayerData.getAll())
|
||||||
|
if (data.isFullyLoaded())
|
||||||
|
provider.getDataManager().saveData(data);
|
||||||
|
|
||||||
|
// Save guild info
|
||||||
|
for (Guild guild : provider.getGuildManager().getAll())
|
||||||
|
provider.getGuildManager().save(guild);
|
||||||
|
} catch (Exception e) {
|
||||||
|
commandSender.sendMessage("Couldn't transfer properly the data.");
|
||||||
|
e.printStackTrace();
|
||||||
|
if(provider!=null&&provider instanceof MySQLDataProvider) {
|
||||||
|
((MySQLDataProvider) provider).close();
|
||||||
|
}
|
||||||
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
|
DataProvider finalProvider = provider;
|
||||||
|
|
||||||
|
//We close the connection 10 s later to avoid memory leaks.
|
||||||
|
new BukkitRunnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if(finalProvider !=null&& finalProvider instanceof MySQLDataProvider) {
|
||||||
|
((MySQLDataProvider) finalProvider).close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(MMOCore.plugin,200);
|
||||||
|
|
||||||
|
|
||||||
|
return CommandResult.SUCCESS;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -110,7 +110,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//We now change the saved status to false because the data on SQL won't be the same as in the RAM
|
//We now change the saved status to false because the data on SQL won't be the same as in the RAM
|
||||||
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, data.getUniqueId());
|
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, data.getUniqueId(),provider);
|
||||||
|
|
||||||
//We set the saved status to false
|
//We set the saved status to false
|
||||||
sql.updateData("is_saved", 0);
|
sql.updateData("is_saved", 0);
|
||||||
@ -155,7 +155,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
@Override
|
@Override
|
||||||
public void saveData(PlayerData data) {
|
public void saveData(PlayerData data) {
|
||||||
|
|
||||||
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, data.getUniqueId());
|
MySQLTableEditor sql = new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, data.getUniqueId(),provider);
|
||||||
MMOCore.sqlDebug("Saving data for: '" + data.getUniqueId() + "'...");
|
MMOCore.sqlDebug("Saving data for: '" + data.getUniqueId() + "'...");
|
||||||
|
|
||||||
sql.updateData("class_points", data.getClassPoints());
|
sql.updateData("class_points", data.getClassPoints());
|
||||||
@ -232,7 +232,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
@Override
|
@Override
|
||||||
public void removeFriend(UUID uuid) {
|
public void removeFriend(UUID uuid) {
|
||||||
friends.remove(uuid);
|
friends.remove(uuid);
|
||||||
new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, uuid).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
|
new MySQLTableEditor(MySQLTableEditor.Table.PLAYERDATA, uuid,provider).updateData("friends", friends.stream().map(UUID::toString).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,13 +14,16 @@ public class MySQLTableEditor {
|
|||||||
private final Table table;
|
private final Table table;
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
||||||
public MySQLTableEditor(Table table, UUID uuid) {
|
private final MySQLDataProvider provider;
|
||||||
|
|
||||||
|
public MySQLTableEditor(Table table, UUID uuid,MySQLDataProvider provider) {
|
||||||
this.table = table;
|
this.table = table;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
this.provider=provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateData(String key, Object value) {
|
public void updateData(String key, Object value) {
|
||||||
((MySQLDataProvider) MMOCore.plugin.dataProvider).executeUpdate("INSERT INTO " + table + "(uuid, " + key
|
provider.executeUpdate("INSERT INTO " + table + "(uuid, " + key
|
||||||
+ ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
|
+ ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user