mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-25 12:05:16 +01:00
Class register should be in the main thread
This commit is contained in:
parent
030e6b2890
commit
0abdf99c85
@ -95,6 +95,7 @@ import com.gamingmesh.jobs.economy.BufferedEconomy;
|
||||
import com.gamingmesh.jobs.economy.BufferedPayment;
|
||||
import com.gamingmesh.jobs.economy.Economy;
|
||||
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.McMMO2_X_listener;
|
||||
import com.gamingmesh.jobs.McMMO.McMMOManager;
|
||||
@ -184,6 +185,8 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
protected static SelectionManager smanager = null;
|
||||
|
||||
private static PointsData pointsDatabase = null;
|
||||
|
||||
private void setMcMMOlistener() {
|
||||
try {
|
||||
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
|
||||
@ -319,6 +322,17 @@ public class Jobs extends JavaPlugin {
|
||||
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() {
|
||||
shopManager = new ShopManager();
|
||||
}
|
||||
@ -904,6 +918,7 @@ public class Jobs extends JavaPlugin {
|
||||
setPermissionHandler(new PermissionHandler(this));
|
||||
setPluginLogger(getLogger());
|
||||
setJobsClassloader();
|
||||
setPointsDatabase();
|
||||
setDBManager();
|
||||
setLanguage();
|
||||
setGUIManager();
|
||||
|
@ -397,12 +397,12 @@ public class Placeholder {
|
||||
case user_totallevels:
|
||||
return Integer.toString(user.getTotalLevels());
|
||||
case user_points:
|
||||
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
|
||||
PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
|
||||
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
return format.format(pointInfo.getCurrentPoints());
|
||||
case user_total_points:
|
||||
format = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
|
||||
pointInfo = Jobs.getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
|
||||
return format.format(pointInfo.getTotalPoints());
|
||||
case user_issaved:
|
||||
return convert(user.isSaved());
|
||||
|
@ -62,7 +62,6 @@ import com.gamingmesh.jobs.container.PlayerPoints;
|
||||
import com.gamingmesh.jobs.dao.JobsDAO;
|
||||
import com.gamingmesh.jobs.dao.JobsDAOData;
|
||||
import com.gamingmesh.jobs.economy.PaymentData;
|
||||
import com.gamingmesh.jobs.economy.PointsData;
|
||||
import com.gamingmesh.jobs.stuff.PerformCommands;
|
||||
import com.gamingmesh.jobs.stuff.Util;
|
||||
|
||||
@ -73,17 +72,12 @@ public class PlayerManager {
|
||||
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<UUID, JobsPlayer> playersUUID = new ConcurrentHashMap<>();
|
||||
|
||||
private PointsData PointsDatabase = new PointsData();
|
||||
private final String mobSpawnerMetadata = "jobsMobSpawner";
|
||||
|
||||
private HashMap<UUID, PlayerInfo> PlayerUUIDMap = new HashMap<>();
|
||||
private HashMap<Integer, PlayerInfo> PlayerIDMap = new HashMap<>();
|
||||
private HashMap<String, PlayerInfo> PlayerNameMap = new HashMap<>();
|
||||
|
||||
public PointsData getPointsData() {
|
||||
return PointsDatabase;
|
||||
}
|
||||
|
||||
public int getMapSize() {
|
||||
return PlayerUUIDMap.size();
|
||||
}
|
||||
@ -324,9 +318,9 @@ public class PlayerManager {
|
||||
}
|
||||
|
||||
if (points != null)
|
||||
getPointsData().addPlayer(jPlayer.getPlayerUUID(), points);
|
||||
Jobs.getPointsData().addPlayer(jPlayer.getPlayerUUID(), points);
|
||||
else
|
||||
getPointsData().addPlayer(jPlayer.getPlayerUUID());
|
||||
Jobs.getPointsData().addPlayer(jPlayer.getPlayerUUID());
|
||||
|
||||
if (logs != null)
|
||||
jPlayer.setLog(logs);
|
||||
@ -549,7 +543,7 @@ public class PlayerManager {
|
||||
if (Jobs.getGCManager().LevelChangeChat)
|
||||
player.sendMessage(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
|
@ -33,7 +33,7 @@ public class editpoints implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID());
|
||||
PlayerPoints pointInfo = Jobs.getPointsData().getPlayerPointsInfo(jPlayer.getPlayerUUID());
|
||||
|
||||
if (pointInfo == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", jPlayer.getUserName()));
|
||||
|
@ -38,7 +38,7 @@ public class points implements Cmd {
|
||||
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("command.points.currentpoints", "%currentpoints%", (int) (pointInfo.getCurrentPoints() * 100) / 100D));
|
||||
|
@ -71,7 +71,7 @@ public class ShopManager {
|
||||
return;
|
||||
|
||||
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")) {
|
||||
for (String onePerm : item.getRequiredPerm()) {
|
||||
@ -193,7 +193,7 @@ public class ShopManager {
|
||||
if (title.length() > 32)
|
||||
title = title.substring(0, 30) + "..";
|
||||
|
||||
PlayerPoints pointsInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(player.getUniqueId());
|
||||
PlayerPoints pointsInfo = Jobs.getPointsData().getPlayerPointsInfo(player.getUniqueId());
|
||||
double points = 0D;
|
||||
if (pointsInfo != null)
|
||||
points = (int) (pointsInfo.getCurrentPoints() * 100.0) / 100.0;
|
||||
|
@ -1,50 +1,51 @@
|
||||
package com.gamingmesh.jobs.dao;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
|
||||
public class JobsConnectionPool {
|
||||
|
||||
private JobsConnection connection;
|
||||
private String url;
|
||||
private String username;
|
||||
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();
|
||||
JobsDrivers jDriver = new JobsDrivers(driver);
|
||||
DriverManager.registerDriver(jDriver);
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = 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();
|
||||
JobsDrivers jDriver = new JobsDrivers(driver);
|
||||
DriverManager.registerDriver(jDriver);
|
||||
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
public synchronized JobsConnection getConnection() throws SQLException {
|
||||
if (connection != null && (connection.isClosed() || !connection.isValid(1))) {
|
||||
try {
|
||||
connection.closeConnection();
|
||||
} catch (SQLException e) {}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
if (connection == null) {
|
||||
Connection conn = DriverManager.getConnection(url, username, password);
|
||||
connection = new JobsConnection(conn);
|
||||
}
|
||||
|
||||
return connection;
|
||||
if (connection != null && (connection.isClosed() || !connection.isValid(1))) {
|
||||
try {
|
||||
connection.closeConnection();
|
||||
} catch (SQLException e) {}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
if (connection == null) {
|
||||
connection = new JobsConnection(DriverManager.getConnection(url, username, password));
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
public synchronized void closeConnection() {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.closeConnection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.closeConnection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1430,7 +1430,7 @@ public abstract class JobsDAO {
|
||||
|
||||
PreparedStatement prest = null;
|
||||
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.setDouble(1, pointInfo.getTotalPoints());
|
||||
prest.setDouble(2, pointInfo.getCurrentPoints());
|
||||
@ -1455,9 +1455,9 @@ public abstract class JobsDAO {
|
||||
res = prest.executeQuery();
|
||||
|
||||
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 {
|
||||
Jobs.getPlayerManager().getPointsData().addPlayer(player.getPlayerUUID());
|
||||
Jobs.getPointsData().addPlayer(player.getPlayerUUID());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -130,7 +130,6 @@ public class JobsMySQL extends JobsDAO {
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage());
|
||||
close(statement);
|
||||
return false;
|
||||
} finally {
|
||||
close(statement);
|
||||
|
@ -10,6 +10,9 @@ public class PointsData {
|
||||
|
||||
private HashMap<UUID, PlayerPoints> Pointbase = new HashMap<>();
|
||||
|
||||
public PointsData() {
|
||||
}
|
||||
|
||||
public HashMap<UUID, PlayerPoints> getPointBase() {
|
||||
return Pointbase;
|
||||
}
|
||||
@ -29,6 +32,7 @@ public class PointsData {
|
||||
public void addPlayer(UUID uuid, PlayerPoints points) {
|
||||
if (Jobs.getGCManager().MultiServerCompatability() && Pointbase.containsKey(uuid))
|
||||
Pointbase.remove(uuid);
|
||||
|
||||
if (!Pointbase.containsKey(uuid))
|
||||
Pointbase.put(uuid, points);
|
||||
}
|
||||
|
@ -46,6 +46,6 @@ public class BufferedPaymentTask implements Runnable {
|
||||
}
|
||||
|
||||
if (payment.getPoints() != 0D)
|
||||
Jobs.getPlayerManager().getPointsData().addPoints(payment.getOfflinePlayer().getUniqueId(), payment.getPoints());
|
||||
Jobs.getPointsData().addPoints(payment.getOfflinePlayer().getUniqueId(), payment.getPoints());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user