1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Class register should be in the main thread

This commit is contained in:
montlikadani 2019-07-28 12:39:31 +02:00
parent 030e6b2890
commit 0abdf99c85
11 changed files with 64 additions and 51 deletions

View File

@ -95,6 +95,7 @@ import com.gamingmesh.jobs.economy.BufferedEconomy;
import com.gamingmesh.jobs.economy.BufferedPayment; import com.gamingmesh.jobs.economy.BufferedPayment;
import com.gamingmesh.jobs.economy.Economy; import com.gamingmesh.jobs.economy.Economy;
import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.McMMO.McMMO1_X_listener; import com.gamingmesh.jobs.McMMO.McMMO1_X_listener;
import com.gamingmesh.jobs.McMMO.McMMO2_X_listener; import com.gamingmesh.jobs.McMMO.McMMO2_X_listener;
import com.gamingmesh.jobs.McMMO.McMMOManager; import com.gamingmesh.jobs.McMMO.McMMOManager;
@ -184,6 +185,8 @@ public class Jobs extends JavaPlugin {
protected static SelectionManager smanager = null; protected static SelectionManager smanager = null;
private static PointsData pointsDatabase = null;
private void setMcMMOlistener() { private void setMcMMOlistener() {
try { try {
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType"); Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
@ -319,6 +322,17 @@ public class Jobs extends JavaPlugin {
return DBManager; return DBManager;
} }
public static void setPointsDatabase() {
pointsDatabase = new PointsData();
}
public static PointsData getPointsData() {
if (pointsDatabase == null)
pointsDatabase = new PointsData();
return pointsDatabase;
}
public static void setShopManager() { public static void setShopManager() {
shopManager = new ShopManager(); shopManager = new ShopManager();
} }
@ -904,6 +918,7 @@ public class Jobs extends JavaPlugin {
setPermissionHandler(new PermissionHandler(this)); setPermissionHandler(new PermissionHandler(this));
setPluginLogger(getLogger()); setPluginLogger(getLogger());
setJobsClassloader(); setJobsClassloader();
setPointsDatabase();
setDBManager(); setDBManager();
setLanguage(); setLanguage();
setGUIManager(); setGUIManager();

View File

@ -397,12 +397,12 @@ public class Placeholder {
case user_totallevels: case user_totallevels:
return Integer.toString(user.getTotalLevels()); return Integer.toString(user.getTotalLevels());
case user_points: case user_points:
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID()); PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH); NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
return format.format(pointInfo.getCurrentPoints()); return format.format(pointInfo.getCurrentPoints());
case user_total_points: case user_total_points:
format = NumberFormat.getInstance(Locale.ENGLISH); format = NumberFormat.getInstance(Locale.ENGLISH);
pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID()); pointInfo = Jobs.getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
return format.format(pointInfo.getTotalPoints()); return format.format(pointInfo.getTotalPoints());
case user_issaved: case user_issaved:
return convert(user.isSaved()); return convert(user.isSaved());

View File

@ -62,7 +62,6 @@ import com.gamingmesh.jobs.container.PlayerPoints;
import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.dao.JobsDAOData; import com.gamingmesh.jobs.dao.JobsDAOData;
import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.economy.PaymentData;
import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.stuff.PerformCommands; import com.gamingmesh.jobs.stuff.PerformCommands;
import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.stuff.Util;
@ -73,17 +72,12 @@ public class PlayerManager {
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<>();
private ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<>(); private ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<>();
private PointsData PointsDatabase = new PointsData();
private final String mobSpawnerMetadata = "jobsMobSpawner"; private final String mobSpawnerMetadata = "jobsMobSpawner";
private HashMap<UUID, PlayerInfo> PlayerUUIDMap = new HashMap<>(); private HashMap<UUID, PlayerInfo> PlayerUUIDMap = new HashMap<>();
private HashMap<Integer, PlayerInfo> PlayerIDMap = new HashMap<>(); private HashMap<Integer, PlayerInfo> PlayerIDMap = new HashMap<>();
private HashMap<String, PlayerInfo> PlayerNameMap = new HashMap<>(); private HashMap<String, PlayerInfo> PlayerNameMap = new HashMap<>();
public PointsData getPointsData() {
return PointsDatabase;
}
public int getMapSize() { public int getMapSize() {
return PlayerUUIDMap.size(); return PlayerUUIDMap.size();
} }
@ -324,9 +318,9 @@ public class PlayerManager {
} }
if (points != null) if (points != null)
getPointsData().addPlayer(jPlayer.getPlayerUUID(), points); Jobs.getPointsData().addPlayer(jPlayer.getPlayerUUID(), points);
else else
getPointsData().addPlayer(jPlayer.getPlayerUUID()); Jobs.getPointsData().addPlayer(jPlayer.getPlayerUUID());
if (logs != null) if (logs != null)
jPlayer.setLog(logs); jPlayer.setLog(logs);
@ -549,7 +543,7 @@ public class PlayerManager {
if (Jobs.getGCManager().LevelChangeChat) if (Jobs.getGCManager().LevelChangeChat)
player.sendMessage(line); player.sendMessage(line);
} }
} }
jPlayer.reloadHonorific(); jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer); Jobs.getPermissionHandler().recalculatePermissions(jPlayer);

View File

@ -33,7 +33,7 @@ public class editpoints implements Cmd {
return true; return true;
} }
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID()); PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID());
if (pointInfo == null) { if (pointInfo == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", jPlayer.getUserName())); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", jPlayer.getUserName()));

View File

@ -38,7 +38,7 @@ public class points implements Cmd {
return true; return true;
} }
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID()); PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID());
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getUserName())); sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getUserName()));
sender.sendMessage(Jobs.getLanguage().getMessage("command.points.currentpoints", "%currentpoints%", (int) (pointInfo.getCurrentPoints() * 100) / 100D)); sender.sendMessage(Jobs.getLanguage().getMessage("command.points.currentpoints", "%currentpoints%", (int) (pointInfo.getCurrentPoints() * 100) / 100D));

View File

@ -71,7 +71,7 @@ public class ShopManager {
return; return;
ShopItem item = ls.get(slot); ShopItem item = ls.get(slot);
PlayerPoints pointsInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(player.getUniqueId()); PlayerPoints pointsInfo = Jobs.getPointsData().getPlayerPointsInfo(player.getUniqueId());
//if (!player.hasPermission("jobs.items.bypass")) { //if (!player.hasPermission("jobs.items.bypass")) {
for (String onePerm : item.getRequiredPerm()) { for (String onePerm : item.getRequiredPerm()) {
@ -193,7 +193,7 @@ public class ShopManager {
if (title.length() > 32) if (title.length() > 32)
title = title.substring(0, 30) + ".."; title = title.substring(0, 30) + "..";
PlayerPoints pointsInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(player.getUniqueId()); PlayerPoints pointsInfo = Jobs.getPointsData().getPlayerPointsInfo(player.getUniqueId());
double points = 0D; double points = 0D;
if (pointsInfo != null) if (pointsInfo != null)
points = (int) (pointsInfo.getCurrentPoints() * 100.0) / 100.0; points = (int) (pointsInfo.getCurrentPoints() * 100.0) / 100.0;

View File

@ -1,50 +1,51 @@
package com.gamingmesh.jobs.dao; package com.gamingmesh.jobs.dao;
import java.sql.Connection;
import java.sql.Driver; import java.sql.Driver;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
public class JobsConnectionPool { public class JobsConnectionPool {
private JobsConnection connection; private JobsConnection connection;
private String url; private String url;
private String username; private String username;
private String password; private String password;
public JobsConnectionPool(String driverName, String url, String username, String password) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
Driver driver = (Driver) Class.forName(driverName, true, Jobs.getJobsClassloader()).newInstance(); public JobsConnectionPool(String driverName, String url, String username, String password)
JobsDrivers jDriver = new JobsDrivers(driver); throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
DriverManager.registerDriver(jDriver); Driver driver = (Driver) Class.forName(driverName, true, Jobs.getJobsClassloader()).newInstance();
this.url = url; JobsDrivers jDriver = new JobsDrivers(driver);
this.username = username; DriverManager.registerDriver(jDriver);
this.password = password;
this.url = url;
this.username = username;
this.password = password;
} }
public synchronized JobsConnection getConnection() throws SQLException { public synchronized JobsConnection getConnection() throws SQLException {
if (connection != null && (connection.isClosed() || !connection.isValid(1))) { if (connection != null && (connection.isClosed() || !connection.isValid(1))) {
try { try {
connection.closeConnection(); connection.closeConnection();
} catch (SQLException e) {} } catch (SQLException e) {}
connection = null; connection = null;
} }
if (connection == null) { if (connection == null) {
Connection conn = DriverManager.getConnection(url, username, password); connection = new JobsConnection(DriverManager.getConnection(url, username, password));
connection = new JobsConnection(conn); }
}
return connection; return connection;
} }
public synchronized void closeConnection() { public synchronized void closeConnection() {
if (connection != null) { if (connection != null) {
try { try {
connection.closeConnection(); connection.closeConnection();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }

View File

@ -1430,7 +1430,7 @@ public abstract class JobsDAO {
PreparedStatement prest = null; PreparedStatement prest = null;
try { try {
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID()); PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID());
prest = conn.prepareStatement("INSERT INTO `" + prefix + "points` (`totalpoints`, `currentpoints`, `userid`) VALUES (?, ?, ?);"); prest = conn.prepareStatement("INSERT INTO `" + prefix + "points` (`totalpoints`, `currentpoints`, `userid`) VALUES (?, ?, ?);");
prest.setDouble(1, pointInfo.getTotalPoints()); prest.setDouble(1, pointInfo.getTotalPoints());
prest.setDouble(2, pointInfo.getCurrentPoints()); prest.setDouble(2, pointInfo.getCurrentPoints());
@ -1455,9 +1455,9 @@ public abstract class JobsDAO {
res = prest.executeQuery(); res = prest.executeQuery();
if (res.next()) { if (res.next()) {
Jobs.getPlayerManager().getPointsData().addPlayer(player.getPlayerUUID(), res.getDouble("currentpoints"), res.getDouble("totalpoints")); Jobs.getPointsData().addPlayer(player.getPlayerUUID(), res.getDouble("currentpoints"), res.getDouble("totalpoints"));
} else { } else {
Jobs.getPlayerManager().getPointsData().addPlayer(player.getPlayerUUID()); Jobs.getPointsData().addPlayer(player.getPlayerUUID());
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -130,7 +130,6 @@ public class JobsMySQL extends JobsDAO {
statement.close(); statement.close();
} catch (SQLException e) { } catch (SQLException e) {
Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage()); Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage());
close(statement);
return false; return false;
} finally { } finally {
close(statement); close(statement);

View File

@ -10,6 +10,9 @@ public class PointsData {
private HashMap<UUID, PlayerPoints> Pointbase = new HashMap<>(); private HashMap<UUID, PlayerPoints> Pointbase = new HashMap<>();
public PointsData() {
}
public HashMap<UUID, PlayerPoints> getPointBase() { public HashMap<UUID, PlayerPoints> getPointBase() {
return Pointbase; return Pointbase;
} }
@ -29,6 +32,7 @@ public class PointsData {
public void addPlayer(UUID uuid, PlayerPoints points) { public void addPlayer(UUID uuid, PlayerPoints points) {
if (Jobs.getGCManager().MultiServerCompatability() && Pointbase.containsKey(uuid)) if (Jobs.getGCManager().MultiServerCompatability() && Pointbase.containsKey(uuid))
Pointbase.remove(uuid); Pointbase.remove(uuid);
if (!Pointbase.containsKey(uuid)) if (!Pointbase.containsKey(uuid))
Pointbase.put(uuid, points); Pointbase.put(uuid, points);
} }

View File

@ -46,6 +46,6 @@ public class BufferedPaymentTask implements Runnable {
} }
if (payment.getPoints() != 0D) if (payment.getPoints() != 0D)
Jobs.getPlayerManager().getPointsData().addPoints(payment.getOfflinePlayer().getUniqueId(), payment.getPoints()); Jobs.getPointsData().addPoints(payment.getOfflinePlayer().getUniqueId(), payment.getPoints());
} }
} }