mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-08 01:08:23 +01:00
Improve database loading
This commit is contained in:
parent
a9c94d36d8
commit
47280b04d0
@ -59,6 +59,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -510,9 +511,31 @@ public class Jobs extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Executes close connections
|
* Executes close connections
|
||||||
*/
|
*/
|
||||||
public static void ChangeDatabase() {
|
public static void convertDatabase() {
|
||||||
getDBManager().switchDataBase();
|
try {
|
||||||
getPlayerManager().reload();
|
List<Convert> archivelist = dao.convertDatabase();
|
||||||
|
|
||||||
|
getDBManager().switchDataBase();
|
||||||
|
getPlayerManager().reload();
|
||||||
|
|
||||||
|
dao.truncateAllTables();
|
||||||
|
getPlayerManager().convertChacheOfPlayers(true);
|
||||||
|
|
||||||
|
dao.continueConvertions(archivelist);
|
||||||
|
getPlayerManager().clearMaps();
|
||||||
|
getPlayerManager().clearCache();
|
||||||
|
|
||||||
|
dao.saveExplore();
|
||||||
|
// Do we really need to convert Block protection?
|
||||||
|
// Jobs.getJobsDAO().saveBlockProtection();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reload();
|
||||||
|
loadAllPlayersData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -592,14 +615,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
setEnabled(true);
|
|
||||||
|
|
||||||
if (instance == null) {
|
|
||||||
System.out.println("Plugin instance is null. Plugin will be disabled.");
|
|
||||||
System.out.println("Try restart your server completely. If this not work contact the developers.");
|
|
||||||
setEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// itemManager = new ItemManager(this);
|
// itemManager = new ItemManager(this);
|
||||||
|
|
||||||
@ -625,7 +640,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
||||||
jobConfig.saveDefaultConfig();
|
jobConfig.saveDefaultConfig();
|
||||||
|
|
||||||
@ -673,7 +687,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
getCommandManager().fillCommands();
|
getCommandManager().fillCommands();
|
||||||
|
|
||||||
getDBManager().getDB().triggerTableIdUpdate();
|
getDBManager().getDB().triggerTableIdUpdate();
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled.");
|
System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled.");
|
||||||
@ -727,11 +740,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
|
|
||||||
getGCManager().reload();
|
getGCManager().reload();
|
||||||
getLanguage().reload();
|
getLanguage().reload();
|
||||||
try {
|
getConfigManager().reload();
|
||||||
getConfigManager().reload();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
getDBManager().getDB().loadAllJobsWorlds();
|
getDBManager().getDB().loadAllJobsWorlds();
|
||||||
getDBManager().getDB().loadAllJobsNames();
|
getDBManager().getDB().loadAllJobsNames();
|
||||||
@ -740,7 +749,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
ToggleBarHandling.load();
|
ToggleBarHandling.load();
|
||||||
usedSlots.clear();
|
usedSlots.clear();
|
||||||
for (Job job : jobs) {
|
for (Job job : jobs) {
|
||||||
usedSlots.put(job, dao.getSlotsTaken(job));
|
usedSlots.put(job, getDBManager().getDB().getSlotsTaken(job));
|
||||||
}
|
}
|
||||||
getPlayerManager().reload();
|
getPlayerManager().reload();
|
||||||
getPermissionHandler().registerPermissions();
|
getPermissionHandler().registerPermissions();
|
||||||
@ -755,7 +764,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
paymentThread = new BufferedPaymentThread(getGCManager().getEconomyBatchDelay());
|
paymentThread = new BufferedPaymentThread(getGCManager().getEconomyBatchDelay());
|
||||||
paymentThread.start();
|
paymentThread.start();
|
||||||
|
|
||||||
dao.loadPlayerData();
|
getDBManager().getDB().loadPlayerData();
|
||||||
|
|
||||||
// Schedule
|
// Schedule
|
||||||
if (getGCManager().enableSchedule) {
|
if (getGCManager().enableSchedule) {
|
||||||
@ -771,17 +780,14 @@ public class Jobs extends JavaPlugin {
|
|||||||
if (instance == null)
|
if (instance == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
// GUIManager.CloseInventories();
|
||||||
// GUIManager.CloseInventories();
|
// shopManager.CloseInventories();
|
||||||
// shopManager.CloseInventories();
|
dao.saveExplore();
|
||||||
dao.saveExplore();
|
|
||||||
|
getBpManager().saveCache();
|
||||||
|
FurnaceBrewingHandling.save();
|
||||||
|
ToggleBarHandling.save();
|
||||||
|
|
||||||
getBpManager().saveCache();
|
|
||||||
FurnaceBrewingHandling.save();
|
|
||||||
ToggleBarHandling.save();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
shutdown();
|
shutdown();
|
||||||
instance = null;
|
instance = null;
|
||||||
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
|
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
|
||||||
|
@ -114,8 +114,7 @@ public class PlayerManager {
|
|||||||
public void addPlayerToMap(PlayerInfo info) {
|
public void addPlayerToMap(PlayerInfo info) {
|
||||||
PlayerUUIDMap.put(info.getUuid(), info);
|
PlayerUUIDMap.put(info.getUuid(), info);
|
||||||
PlayerIDMap.put(info.getID(), info);
|
PlayerIDMap.put(info.getID(), info);
|
||||||
if (info.getName() != null)
|
PlayerNameMap.put(info.getName().toLowerCase(), info);
|
||||||
PlayerNameMap.put(info.getName().toLowerCase(), info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayerToCache(JobsPlayer jPlayer) {
|
public void addPlayerToCache(JobsPlayer jPlayer) {
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package com.gamingmesh.jobs.commands.list;
|
package com.gamingmesh.jobs.commands.list;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -10,7 +7,6 @@ import org.bukkit.entity.Player;
|
|||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.commands.Cmd;
|
import com.gamingmesh.jobs.commands.Cmd;
|
||||||
import com.gamingmesh.jobs.commands.JobCommand;
|
import com.gamingmesh.jobs.commands.JobCommand;
|
||||||
import com.gamingmesh.jobs.container.Convert;
|
|
||||||
import com.gamingmesh.jobs.dao.JobsManager.DataBaseType;
|
import com.gamingmesh.jobs.dao.JobsManager.DataBaseType;
|
||||||
|
|
||||||
public class convert implements Cmd {
|
public class convert implements Cmd {
|
||||||
@ -28,41 +24,7 @@ public class convert implements Cmd {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> Jobs.convertDatabase());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
List<Convert> archivelist = null;
|
|
||||||
try {
|
|
||||||
archivelist = Jobs.getJobsDAO().convertDatabase();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Jobs.ChangeDatabase();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Jobs.getJobsDAO().truncateAllTables();
|
|
||||||
Jobs.getPlayerManager().convertChacheOfPlayers(true);
|
|
||||||
|
|
||||||
Jobs.getJobsDAO().continueConvertions(archivelist);
|
|
||||||
Jobs.getPlayerManager().clearMaps();
|
|
||||||
Jobs.getPlayerManager().clearCache();
|
|
||||||
|
|
||||||
Jobs.getJobsDAO().saveExplore();
|
|
||||||
// Do we really need to convert Block protection?
|
|
||||||
// Jobs.getJobsDAO().saveBlockProtection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Jobs.reload();
|
|
||||||
Jobs.loadAllPlayersData();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String from = "MySQL";
|
String from = "MySQL";
|
||||||
String to = "SQLite";
|
String to = "SQLite";
|
||||||
|
@ -269,9 +269,13 @@ public class ConfigManager {
|
|||||||
cfg.save();
|
cfg.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() throws IOException {
|
public void reload() {
|
||||||
// job settings
|
// job settings
|
||||||
loadJobSettings();
|
try {
|
||||||
|
loadJobSettings();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public YamlConfiguration getJobConfig() {
|
public YamlConfiguration getJobConfig() {
|
||||||
|
@ -649,21 +649,20 @@ public abstract class JobsDAO {
|
|||||||
res = prest.executeQuery();
|
res = prest.executeQuery();
|
||||||
while (res.next()) {
|
while (res.next()) {
|
||||||
int id = res.getInt(JobsTableFields.userid.getCollumn());
|
int id = res.getInt(JobsTableFields.userid.getCollumn());
|
||||||
List<JobsDAOData> ls = map.get(id);
|
String jobName = res.getString(JobsTableFields.job.getCollumn());
|
||||||
if (ls == null)
|
List<JobsDAOData> ls = new ArrayList<>();
|
||||||
ls = new ArrayList<>();
|
|
||||||
|
|
||||||
int jobId = res.getInt(JobsTableFields.jobid.getCollumn());
|
int jobId = res.getInt(JobsTableFields.jobid.getCollumn());
|
||||||
if (jobId == 0) {
|
if (jobId == 0) {
|
||||||
ls.add(new JobsDAOData(res.getString(JobsTableFields.job.getCollumn()), res.getInt(JobsTableFields.level.getCollumn()), res.getDouble(JobsTableFields.experience.getCollumn())));
|
ls.add(new JobsDAOData(jobName, res.getInt(JobsTableFields.level.getCollumn()), res.getDouble(JobsTableFields.experience.getCollumn())));
|
||||||
converted = false;
|
converted = false;
|
||||||
} else {
|
} else {
|
||||||
// This should be removed when we switch over to id only method
|
// This should be removed when we switch over to id only method
|
||||||
if (converted)
|
if (converted)
|
||||||
if (res.getString(JobsTableFields.job.getCollumn()) == null || res.getString(JobsTableFields.job.getCollumn()).isEmpty())
|
if (jobName == null || jobName.isEmpty())
|
||||||
converted = false;
|
converted = false;
|
||||||
|
|
||||||
Job job = Jobs.getJob(jobId);
|
Job job = Jobs.getJob(jobName);
|
||||||
if (job != null)
|
if (job != null)
|
||||||
ls.add(new JobsDAOData(job.getName(), res.getInt(JobsTableFields.level.getCollumn()), res.getDouble(JobsTableFields.experience.getCollumn())));
|
ls.add(new JobsDAOData(job.getName(), res.getInt(JobsTableFields.level.getCollumn()), res.getDouble(JobsTableFields.experience.getCollumn())));
|
||||||
}
|
}
|
||||||
@ -1479,13 +1478,7 @@ public abstract class JobsDAO {
|
|||||||
String jobName = res.getString(ArchiveTableFields.job.getCollumn());
|
String jobName = res.getString(ArchiveTableFields.job.getCollumn());
|
||||||
int jobid = res.getInt(ArchiveTableFields.jobid.getCollumn());
|
int jobid = res.getInt(ArchiveTableFields.jobid.getCollumn());
|
||||||
|
|
||||||
Job job = null;
|
Job job = jobid != 0 ? Jobs.getJob(jobid) : Jobs.getJob(jobName);
|
||||||
if (jobid != 0) {
|
|
||||||
job = Jobs.getJob(jobid);
|
|
||||||
} else {
|
|
||||||
job = Jobs.getJob(jobName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (job == null)
|
if (job == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1740,27 +1733,26 @@ public abstract class JobsDAO {
|
|||||||
|
|
||||||
public void loadPlayerData() {
|
public void loadPlayerData() {
|
||||||
Jobs.getPlayerManager().clearMaps();
|
Jobs.getPlayerManager().clearMaps();
|
||||||
|
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PreparedStatement prest = null;
|
PreparedStatement prest = null;
|
||||||
ResultSet res = null;
|
ResultSet res = null;
|
||||||
try {
|
try {
|
||||||
prest = conn.prepareStatement("SELECT * FROM `" + DBTables.UsersTable.getTableName() + "`;");
|
prest = conn.prepareStatement("SELECT * FROM `" + DBTables.UsersTable.getTableName() + "`;");
|
||||||
res = prest.executeQuery();
|
res = prest.executeQuery();
|
||||||
while (res.next()) {
|
while (res.next()) {
|
||||||
long seen = System.currentTimeMillis();
|
long seen = res.getLong(UserTableFields.seen.getCollumn());
|
||||||
try {
|
|
||||||
seen = res.getLong(UserTableFields.seen.getCollumn());
|
Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo(
|
||||||
Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo(
|
res.getString(UserTableFields.username.getCollumn()),
|
||||||
res.getString(UserTableFields.username.getCollumn()),
|
res.getInt("id"),
|
||||||
res.getInt("id"),
|
UUID.fromString(res.getString(UserTableFields.player_uuid.getCollumn())),
|
||||||
UUID.fromString(res.getString(UserTableFields.player_uuid.getCollumn())),
|
seen,
|
||||||
seen,
|
res.getInt(UserTableFields.donequests.getCollumn()),
|
||||||
res.getInt(UserTableFields.donequests.getCollumn()),
|
res.getString(UserTableFields.quests.getCollumn())));
|
||||||
res.getString(UserTableFields.quests.getCollumn())));
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1768,6 +1760,7 @@ public abstract class JobsDAO {
|
|||||||
close(res);
|
close(res);
|
||||||
close(prest);
|
close(prest);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user