1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Moving to ConcurentHashMap

This commit is contained in:
Zrips 2015-11-25 17:14:48 +02:00
parent ba506a1e62
commit 3d05def4b6
12 changed files with 368 additions and 324 deletions

View File

@ -19,10 +19,8 @@
package com.gamingmesh.jobs; package com.gamingmesh.jobs;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -44,15 +42,15 @@ import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.PerformCommands; import com.gamingmesh.jobs.stuff.PerformCommands;
public class PlayerManager { public class PlayerManager {
private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>()); // private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>());
//private Map<String, JobsPlayer> players = new HashMap<String, JobsPlayer>(); private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<String, JobsPlayer>();
/** /**
* Handles join of new player * Handles join of new player
* @param playername * @param playername
*/ */
public void playerJoin(Player player) { public void playerJoin(Player player) {
synchronized (players) { // synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase()); JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) { if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player); jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
@ -63,7 +61,7 @@ public class PlayerManager {
jPlayer.reloadHonorific(); jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer); Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return; return;
} // }
} }
/** /**
@ -71,7 +69,7 @@ public class PlayerManager {
* @param playername * @param playername
*/ */
public void playerQuit(Player player) { public void playerQuit(Player player) {
synchronized (players) { // synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) { if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase()); JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) { if (jPlayer != null) {
@ -84,7 +82,7 @@ public class PlayerManager {
jPlayer.onDisconnect(); jPlayer.onDisconnect();
} }
} }
} // }
} }
/** /**
@ -101,25 +99,25 @@ public class PlayerManager {
* 3) Garbage collect the real list to remove any offline players with saved data * 3) Garbage collect the real list to remove any offline players with saved data
*/ */
ArrayList<JobsPlayer> list = null; ArrayList<JobsPlayer> list = null;
synchronized (players) { // synchronized (players) {
list = new ArrayList<JobsPlayer>(players.values()); list = new ArrayList<JobsPlayer>(players.values());
} // }
for (JobsPlayer jPlayer : list) { for (JobsPlayer jPlayer : list) {
jPlayer.save(dao); jPlayer.save(dao);
} }
synchronized (players) { // synchronized (players) {
Iterator<JobsPlayer> iter = players.values().iterator(); Iterator<JobsPlayer> iter = players.values().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
JobsPlayer jPlayer = iter.next(); JobsPlayer jPlayer = iter.next();
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
if (!jPlayer.isOnline() && jPlayer.isSaved()) { if (!jPlayer.isOnline() && jPlayer.isSaved()) {
iter.remove(); iter.remove();
} }
// }
} }
} // }
}
} }
/** /**
@ -128,7 +126,9 @@ public class PlayerManager {
* @return the player job info of the player * @return the player job info of the player
*/ */
public JobsPlayer getJobsPlayer(Player player) { public JobsPlayer getJobsPlayer(Player player) {
// synchronized (players) {
return players.get(player.getName().toLowerCase()); return players.get(player.getName().toLowerCase());
// }
} }
/** /**
@ -137,7 +137,9 @@ public class PlayerManager {
* @return the player job info of the player * @return the player job info of the player
*/ */
public JobsPlayer getJobsPlayer(String playerName) { public JobsPlayer getJobsPlayer(String playerName) {
// synchronized (players) {
return players.get(playerName.toLowerCase()); return players.get(playerName.toLowerCase());
// }
} }
/** /**
@ -161,7 +163,7 @@ public class PlayerManager {
* @param job * @param job
*/ */
public void joinJob(JobsPlayer jPlayer, Job job) { public void joinJob(JobsPlayer jPlayer, Job job) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
if (jPlayer.isInJob(job)) if (jPlayer.isInJob(job))
return; return;
// let the user join the job // let the user join the job
@ -181,7 +183,7 @@ public class PlayerManager {
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.updateTotalPlayers(); job.updateTotalPlayers();
} // }
} }
/** /**
@ -190,7 +192,7 @@ public class PlayerManager {
* @param job * @param job
*/ */
public void leaveJob(JobsPlayer jPlayer, Job job) { public void leaveJob(JobsPlayer jPlayer, Job job) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
if (!jPlayer.isInJob(job)) if (!jPlayer.isInJob(job))
return; return;
Jobs.getJobsDAO().recordToArchive(jPlayer, job); Jobs.getJobsDAO().recordToArchive(jPlayer, job);
@ -212,7 +214,7 @@ public class PlayerManager {
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.updateTotalPlayers(); job.updateTotalPlayers();
} // }
} }
/** /**
@ -220,7 +222,7 @@ public class PlayerManager {
* @param jPlayer * @param jPlayer
*/ */
public void leaveAllJobs(JobsPlayer jPlayer) { public void leaveAllJobs(JobsPlayer jPlayer) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
for (JobProgression job : jPlayer.getJobProgression()) { for (JobProgression job : jPlayer.getJobProgression()) {
Jobs.getJobsDAO().quitJob(jPlayer, job.getJob()); Jobs.getJobsDAO().quitJob(jPlayer, job.getJob());
PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob()); PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob());
@ -232,7 +234,7 @@ public class PlayerManager {
} }
jPlayer.leaveAllJobs(); jPlayer.leaveAllJobs();
} // }
} }
/** /**
@ -242,7 +244,7 @@ public class PlayerManager {
* @param newjob - the new job * @param newjob - the new job
*/ */
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) { public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
if (!jPlayer.transferJob(oldjob, newjob, jPlayer)) if (!jPlayer.transferJob(oldjob, newjob, jPlayer))
return; return;
@ -252,7 +254,7 @@ public class PlayerManager {
dao.joinJob(jPlayer, newjob); dao.joinJob(jPlayer, newjob);
newjob.updateTotalPlayers(); newjob.updateTotalPlayers();
jPlayer.save(dao); jPlayer.save(dao);
} // }
} }
/** /**
@ -262,13 +264,13 @@ public class PlayerManager {
* @param levels - number of levels to promote * @param levels - number of levels to promote
*/ */
public void promoteJob(JobsPlayer jPlayer, Job job, int levels) { public void promoteJob(JobsPlayer jPlayer, Job job, int levels) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
jPlayer.promoteJob(job, levels, jPlayer); jPlayer.promoteJob(job, levels, jPlayer);
jPlayer.save(Jobs.getJobsDAO()); jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
} // }
} }
/** /**
@ -278,12 +280,12 @@ public class PlayerManager {
* @param levels - number of levels to demote * @param levels - number of levels to demote
*/ */
public void demoteJob(JobsPlayer jPlayer, Job job, int levels) { public void demoteJob(JobsPlayer jPlayer, Job job, int levels) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
jPlayer.demoteJob(job, levels); jPlayer.demoteJob(job, levels);
jPlayer.save(Jobs.getJobsDAO()); jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
} // }
} }
/** /**
@ -293,7 +295,7 @@ public class PlayerManager {
* @param experience - experience gained * @param experience - experience gained
*/ */
public void addExperience(JobsPlayer jPlayer, Job job, double experience) { public void addExperience(JobsPlayer jPlayer, Job job, double experience) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job); JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null) if (prog == null)
return; return;
@ -304,7 +306,7 @@ public class PlayerManager {
jPlayer.save(Jobs.getJobsDAO()); jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
} // }
} }
/** /**
@ -314,7 +316,7 @@ public class PlayerManager {
* @param experience - experience gained * @param experience - experience gained
*/ */
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) { public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job); JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null) if (prog == null)
return; return;
@ -323,7 +325,7 @@ public class PlayerManager {
jPlayer.save(Jobs.getJobsDAO()); jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
} // }
} }
/** /**
@ -558,7 +560,7 @@ public class PlayerManager {
* Perform reload * Perform reload
*/ */
public void reload() { public void reload() {
synchronized (players) { // synchronized (players) {
for (JobsPlayer jPlayer : players.values()) { for (JobsPlayer jPlayer : players.values()) {
for (JobProgression progression : jPlayer.getJobProgression()) { for (JobProgression progression : jPlayer.getJobProgression()) {
String jobName = progression.getJob().getName(); String jobName = progression.getJob().getName();
@ -572,6 +574,6 @@ public class PlayerManager {
Jobs.getPermissionHandler().recalculatePermissions(jPlayer); Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
} }
} }
} // }
} }
} }

View File

@ -44,6 +44,7 @@ import org.bukkit.scoreboard.ScoreboardManager;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.Gui.GuiTools;
import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.ConfigManager;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.Convert; import com.gamingmesh.jobs.container.Convert;
@ -643,9 +644,9 @@ public class JobsCommands implements CommandExecutor {
return true; return true;
} }
// if (sender instanceof Player) { if (sender instanceof Player) {
// ((Player) sender).openInventory(GuiTools.CreateJobsGUI((Player) sender)); ((Player) sender).openInventory(GuiTools.CreateJobsGUI((Player) sender));
// } }
sender.sendMessage(Language.getMessage("command.browse.output.header")); sender.sendMessage(Language.getMessage("command.browse.output.header"));
for (String line : lines) { for (String line : lines) {

View File

@ -80,11 +80,11 @@ public class JobProgression {
* @param job - the new job to be set * @param job - the new job to be set
*/ */
public void setJob(Job job) { public void setJob(Job job) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
jPlayer.setSaved(false); jPlayer.setSaved(false);
this.job = job; this.job = job;
reloadMaxExperienceAndCheckLevelUp(); reloadMaxExperienceAndCheckLevelUp();
} // }
} }
/** /**
@ -101,11 +101,11 @@ public class JobProgression {
* @return - job level up * @return - job level up
*/ */
public boolean addExperience(double experience) { public boolean addExperience(double experience) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
jPlayer.setSaved(false); jPlayer.setSaved(false);
this.experience += experience; this.experience += experience;
return checkLevelUp(); return checkLevelUp();
} // }
} }
/** /**
@ -129,11 +129,11 @@ public class JobProgression {
* @param level - the new level for this job * @param level - the new level for this job
*/ */
public void setLevel(int level) { public void setLevel(int level) {
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
jPlayer.setSaved(false); jPlayer.setSaved(false);
this.level = level; this.level = level;
reloadMaxExperienceAndCheckLevelUp(); reloadMaxExperienceAndCheckLevelUp();
} // }
} }
/** /**

View File

@ -51,7 +51,7 @@ public class JobsPlayer {
private double VipSpawnerMultiplier = -1; private double VipSpawnerMultiplier = -1;
// save lock // save lock
public final Object saveLock = new Object(); // public final Object saveLock = new Object();
// log // log
private List<Log> logList = new ArrayList<Log>(); private List<Log> logList = new ArrayList<Log>();
@ -66,7 +66,7 @@ public class JobsPlayer {
JobsPlayer jPlayer = new JobsPlayer(player.getName(), player); JobsPlayer jPlayer = new JobsPlayer(player.getName(), player);
jPlayer.playerUUID = player.getUniqueId(); jPlayer.playerUUID = player.getUniqueId();
List<JobsDAOData> list = dao.getAllJobs(player); List<JobsDAOData> list = dao.getAllJobs(player);
synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
jPlayer.progression.clear(); jPlayer.progression.clear();
for (JobsDAOData jobdata : list) { for (JobsDAOData jobdata : list) {
if (Jobs.getJob(jobdata.getJobName()) == null) if (Jobs.getJob(jobdata.getJobName()) == null)
@ -84,7 +84,7 @@ public class JobsPlayer {
} }
jPlayer.reloadMaxExperience(); jPlayer.reloadMaxExperience();
} // }
return jPlayer; return jPlayer;
} }
@ -217,7 +217,7 @@ public class JobsPlayer {
* @param job - the job joined * @param job - the job joined
*/ */
public boolean joinJob(Job job, JobsPlayer jPlayer) { public boolean joinJob(Job job, JobsPlayer jPlayer) {
synchronized (saveLock) { // synchronized (saveLock) {
if (!isInJob(job)) { if (!isInJob(job)) {
int level = 1; int level = 1;
int exp = 0; int exp = 0;
@ -235,7 +235,7 @@ public class JobsPlayer {
return true; return true;
} }
return false; return false;
} // }
} }
/** /**
@ -243,7 +243,7 @@ public class JobsPlayer {
* @param job - the job left * @param job - the job left
*/ */
public boolean leaveJob(Job job) { public boolean leaveJob(Job job) {
synchronized (saveLock) { // synchronized (saveLock) {
JobProgression prog = getJobProgression(job); JobProgression prog = getJobProgression(job);
if (prog != null) { if (prog != null) {
progression.remove(prog); progression.remove(prog);
@ -253,7 +253,7 @@ public class JobsPlayer {
return true; return true;
} }
return false; return false;
} // }
} }
/** /**
@ -261,13 +261,13 @@ public class JobsPlayer {
* @return on success * @return on success
*/ */
public boolean leaveAllJobs() { public boolean leaveAllJobs() {
synchronized (saveLock) { // synchronized (saveLock) {
progression.clear(); progression.clear();
reloadHonorific(); reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(this); Jobs.getPermissionHandler().recalculatePermissions(this);
; ;
return true; return true;
} // }
} }
/** /**
@ -276,7 +276,7 @@ public class JobsPlayer {
* @param levels - number of levels to promote * @param levels - number of levels to promote
*/ */
public void promoteJob(Job job, int levels, JobsPlayer player) { public void promoteJob(Job job, int levels, JobsPlayer player) {
synchronized (saveLock) { // synchronized (saveLock) {
JobProgression prog = getJobProgression(job); JobProgression prog = getJobProgression(job);
if (prog == null) if (prog == null)
return; return;
@ -293,7 +293,7 @@ public class JobsPlayer {
newLevel = maxLevel; newLevel = maxLevel;
} }
setLevel(job, newLevel); setLevel(job, newLevel);
} // }
} }
/** /**
@ -302,7 +302,7 @@ public class JobsPlayer {
* @param levels - number of levels to demote * @param levels - number of levels to demote
*/ */
public void demoteJob(Job job, int levels) { public void demoteJob(Job job, int levels) {
synchronized (saveLock) { // synchronized (saveLock) {
JobProgression prog = getJobProgression(job); JobProgression prog = getJobProgression(job);
if (prog == null) if (prog == null)
return; return;
@ -313,7 +313,7 @@ public class JobsPlayer {
newLevel = 1; newLevel = 1;
} }
setLevel(job, newLevel); setLevel(job, newLevel);
} // }
} }
/** /**
@ -322,7 +322,7 @@ public class JobsPlayer {
* @param level - the level * @param level - the level
*/ */
private void setLevel(Job job, int level) { private void setLevel(Job job, int level) {
synchronized (saveLock) { // synchronized (saveLock) {
JobProgression prog = getJobProgression(job); JobProgression prog = getJobProgression(job);
if (prog == null) if (prog == null)
return; return;
@ -333,7 +333,7 @@ public class JobsPlayer {
Jobs.getPermissionHandler().recalculatePermissions(this); Jobs.getPermissionHandler().recalculatePermissions(this);
; ;
} }
} // }
} }
/** /**
@ -342,7 +342,7 @@ public class JobsPlayer {
* @param newjob - the new job * @param newjob - the new job
*/ */
public boolean transferJob(Job oldjob, Job newjob, JobsPlayer jPlayer) { public boolean transferJob(Job oldjob, Job newjob, JobsPlayer jPlayer) {
synchronized (saveLock) { // synchronized (saveLock) {
if (!isInJob(newjob)) { if (!isInJob(newjob)) {
for (JobProgression prog : progression) { for (JobProgression prog : progression) {
if (!prog.getJob().equals(oldjob)) if (!prog.getJob().equals(oldjob))
@ -367,7 +367,7 @@ public class JobsPlayer {
} }
} }
return false; return false;
} // }
} }
/** /**
@ -474,13 +474,13 @@ public class JobsPlayer {
* @param dao * @param dao
*/ */
public void save(JobsDAO dao) { public void save(JobsDAO dao) {
synchronized (saveLock) { // synchronized (saveLock) {
if (!isSaved()) { if (!isSaved()) {
dao.save(this); dao.save(this);
dao.saveLog(this); dao.saveLog(this);
setSaved(true); setSaved(true);
} }
} // }
} }
/** /**

View File

@ -81,7 +81,10 @@ public abstract class JobsDAO {
checkUpdate4(); checkUpdate4();
checkUpdate5(); checkUpdate5();
version = 5; if (version <= 5)
checkUpdate6();
version = 6;
} finally { } finally {
updateSchemaVersion(version); updateSchemaVersion(version);
} }
@ -97,6 +100,8 @@ public abstract class JobsDAO {
protected abstract void checkUpdate5() throws SQLException; protected abstract void checkUpdate5() throws SQLException;
protected abstract void checkUpdate6() throws SQLException;
/** /**
* Gets the database prefix * Gets the database prefix
* @return the prefix * @return the prefix
@ -168,6 +173,7 @@ public abstract class JobsDAO {
while (res.next()) { while (res.next()) {
count = res.getInt(1); count = res.getInt(1);
} }
res.close();
prest.close(); prest.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -193,6 +199,7 @@ public abstract class JobsDAO {
jobs.add(new JobsDAOData(UUIDUtil.fromBytes(res.getBytes(1)), res.getString(2), res.getInt(3), res.getInt(4))); jobs.add(new JobsDAOData(UUIDUtil.fromBytes(res.getBytes(1)), res.getString(2), res.getInt(3), res.getInt(4)));
} }
prest.close(); prest.close();
res.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -249,6 +256,7 @@ public abstract class JobsDAO {
list.add(new Convert(res.getInt("id"), res.getString("username"), UUIDUtil.fromBytes(res.getBytes("player_uuid")), res.getString("job"), res.getInt( list.add(new Convert(res.getInt("id"), res.getString("username"), UUIDUtil.fromBytes(res.getBytes("player_uuid")), res.getString("job"), res.getInt(
"level"), res.getInt("experience"))); "level"), res.getInt("experience")));
} }
res.close();
prest.close(); prest.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -292,6 +300,7 @@ public abstract class JobsDAO {
insert.executeBatch(); insert.executeBatch();
conns.commit(); conns.commit();
conns.setAutoCommit(true); conns.setAutoCommit(true);
statement.close();
} finally { } finally {
if (insert != null) { if (insert != null) {
try { try {
@ -385,6 +394,7 @@ public abstract class JobsDAO {
info.add(level); info.add(level);
info.add(res.getInt(2)); info.add(res.getInt(2));
} }
res.close();
prest.close(); prest.close();
return info; return info;
} catch (SQLException e) { } catch (SQLException e) {
@ -421,7 +431,7 @@ public abstract class JobsDAO {
names.add(top); names.add(top);
} }
res.close();
prest.close(); prest.close();
return names; return names;
} catch (SQLException e) { } catch (SQLException e) {
@ -461,6 +471,7 @@ public abstract class JobsDAO {
info.add(res.getString(1) + ":" + res.getInt(2) + ":" + level + ":" + res.getInt(3)); info.add(res.getString(1) + ":" + res.getInt(2) + ":" + level + ":" + res.getInt(3));
} }
res.close();
prest.close(); prest.close();
return info; return info;
} catch (SQLException e) { } catch (SQLException e) {
@ -653,6 +664,7 @@ public abstract class JobsDAO {
} else } else
jobs.add(new TopList(res.getString(1), res.getInt(2), res.getInt(3), res.getBytes(4))); jobs.add(new TopList(res.getString(1), res.getInt(2), res.getInt(3), res.getBytes(4)));
} }
res.close();
prest.close(); prest.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -677,6 +689,7 @@ public abstract class JobsDAO {
if (res.next()) { if (res.next()) {
slot = res.getInt(1); slot = res.getInt(1);
} }
res.close();
prest.close(); prest.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -700,6 +713,7 @@ public abstract class JobsDAO {
if (res.next()) { if (res.next()) {
return Integer.valueOf(res.getString(1)); return Integer.valueOf(res.getString(1));
} }
res.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -316,8 +316,18 @@ public class JobsDAOMySQL extends JobsDAO {
try { try {
if (rows == 0) if (rows == 0)
executeSQL("CREATE TABLE `" + getPrefix() executeSQL("CREATE TABLE `" + getPrefix()
+ "log` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(20), `count` int, `money` double, `exp` double);"); + "log` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} finally { } finally {
} }
} }
@Override
protected synchronized void checkUpdate6() throws SQLException {
JobsConnection conn = getConnection();
if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
return;
}
executeSQL("ALTER TABLE `" + getPrefix() + "log` MODIFY `itemname` VARCHAR(60);");
}
} }

View File

@ -287,8 +287,27 @@ public class JobsDAOSQLite extends JobsDAO {
try { try {
if (rows == 0) if (rows == 0)
executeSQL("CREATE TABLE `" + getPrefix() executeSQL("CREATE TABLE `" + getPrefix()
+ "log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(20), `count` int, `money` double, `exp` double);"); + "log` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
} finally { } finally {
} }
} }
@Override
protected synchronized void checkUpdate6() throws SQLException {
JobsConnection conn = getConnection();
if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
return;
}
executeSQL("CREATE TABLE `" + getPrefix()
+ "log_temp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` binary(16) NOT NULL, `username` varchar(20), `time` bigint, `action` varchar(20), `itemname` varchar(60), `count` int, `money` double, `exp` double);");
executeSQL("INSERT INTO `" + getPrefix() + "log_temp` SELECT `id`, `player_uuid`, `username`, `time`, `action`, `itemname`, `count`, `money`, `exp` FROM `"
+ getPrefix() + "log`;");
executeSQL("DROP TABLE IF EXISTS `" + getPrefix() + "log`;");
executeSQL("ALTER TABLE `" + getPrefix() + "log_temp` RENAME TO `" + getPrefix() + "log`;");
}
} }

View File

@ -33,6 +33,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -45,6 +48,8 @@ import org.bukkit.plugin.PluginManager;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.Gui.GuiInfoList;
import com.gamingmesh.jobs.Gui.GuiTools;
import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.ConfigManager;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
@ -60,100 +65,100 @@ public class JobsListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
// @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
// public void onGuiRightClick(InventoryClickEvent event) { public void onGuiRightClick(InventoryClickEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0) if (GuiTools.GuiList.size() == 0)
// return; return;
//
// Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
//
// if (!Gui.GuiTools.GuiList.containsKey(player.getName())) if (!GuiTools.GuiList.containsKey(player.getName()))
// return; return;
//
// if (event.getClick() != ClickType.RIGHT) if (event.getClick() != ClickType.RIGHT)
// return; return;
//
// event.setCancelled(true); event.setCancelled(true);
//
// GuiInfoList joblist = Gui.GuiTools.GuiList.get(player.getName()); GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
//
// if (joblist.isJobInfo()) if (joblist.isJobInfo())
// return; return;
//
// int slot = event.getRawSlot(); int slot = event.getRawSlot();
//
// if (slot < joblist.getJobList().size()) { if (slot < joblist.getJobList().size()) {
// Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName()); Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName());
// player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents()); player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents());
// } }
// } }
//
// @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
// public void onGuiLeftClick(InventoryClickEvent event) { public void onGuiLeftClick(InventoryClickEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0) if (GuiTools.GuiList.size() == 0)
// return; return;
//
// Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
//
// if (!Gui.GuiTools.GuiList.containsKey(player.getName())) if (!GuiTools.GuiList.containsKey(player.getName()))
// return; return;
//
// event.setCancelled(true); event.setCancelled(true);
//
// if (event.getClick() != ClickType.LEFT) if (event.getClick() != ClickType.LEFT)
// return; return;
//
// GuiInfoList joblist = Gui.GuiTools.GuiList.get(player.getName()); GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
//
// if (joblist.isJobInfo()) if (joblist.isJobInfo())
// return; return;
//
// int slot = event.getRawSlot(); int slot = event.getRawSlot();
//
// if (slot < joblist.getJobList().size()) { if (slot < joblist.getJobList().size()) {
// player.closeInventory(); player.closeInventory();
// player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot))); player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot)));
// } }
// } }
//
// @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
// public void onGuiLeftSubClick(InventoryClickEvent event) { public void onGuiLeftSubClick(InventoryClickEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0) if (GuiTools.GuiList.size() == 0)
// return; return;
//
// Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
//
// if (!Gui.GuiTools.GuiList.containsKey(player.getName())) if (!GuiTools.GuiList.containsKey(player.getName()))
// return; return;
//
// event.setCancelled(true); event.setCancelled(true);
//
// if (event.getClick() != ClickType.LEFT) if (event.getClick() != ClickType.LEFT)
// return; return;
//
// GuiInfoList joblist = Gui.GuiTools.GuiList.get(player.getName()); GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
//
// if (!joblist.isJobInfo()) if (!joblist.isJobInfo())
// return; return;
//
// int slot = event.getRawSlot(); int slot = event.getRawSlot();
//
// if (slot == joblist.getbackButton()) { if (slot == joblist.getbackButton()) {
// player.closeInventory(); player.closeInventory();
// player.openInventory(GuiTools.CreateJobsGUI(player)); player.openInventory(GuiTools.CreateJobsGUI(player));
// } }
// } }
//
// @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
// public void onGuiClose(InventoryCloseEvent event) { public void onGuiClose(InventoryCloseEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0) if (GuiTools.GuiList.size() == 0)
// return; return;
//
// Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
//
// if (Gui.GuiTools.GuiList.containsKey(player.getName())) if (GuiTools.GuiList.containsKey(player.getName()))
// Gui.GuiTools.GuiList.remove(player.getName()); GuiTools.GuiList.remove(player.getName());
// } }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
@ -253,7 +258,6 @@ public class JobsListener implements Listener {
if (!(block.getState() instanceof Sign)) if (!(block.getState() instanceof Sign))
return; return;
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
Sign sign = (Sign) block.getState(); Sign sign = (Sign) block.getState();

View File

@ -646,6 +646,7 @@ public class JobsPaymentListener implements Listener {
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT), multiplier, null, armor); Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT), multiplier, null, armor);
} }
} }
return;
} }
}, 1); }, 1);
} }

View File

@ -1,25 +1,20 @@
package com.gamingmesh.jobs.stuff; package com.gamingmesh.jobs.stuff;
import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.ConfigManager;
public class OfflinePlayerList { public class OfflinePlayerList {
private static HashMap<String, OfflinePlayer> map = new HashMap<String, OfflinePlayer>(); private static ConcurrentHashMap<String, OfflinePlayer> map = new ConcurrentHashMap<String, OfflinePlayer>();
private static HashMap<UUID, OfflinePlayer> uuidmap = new HashMap<UUID, OfflinePlayer>(); private static ConcurrentHashMap<UUID, OfflinePlayer> uuidmap = new ConcurrentHashMap<UUID, OfflinePlayer>();
public static void fillList() { public static void fillList() {
Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() { for (OfflinePlayer one : Bukkit.getOfflinePlayers()) {
@Override
public void run() {
OfflinePlayer[] players = Bukkit.getOfflinePlayers();
for (OfflinePlayer one : players) {
if (one == null) if (one == null)
continue; continue;
map.put(one.getName().toLowerCase(), one); map.put(one.getName().toLowerCase(), one);
@ -27,8 +22,6 @@ public class OfflinePlayerList {
} }
return; return;
} }
});
}
public static OfflinePlayer getPlayer(UUID uuid) { public static OfflinePlayer getPlayer(UUID uuid) {
if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData) if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData)

View File

@ -1,7 +1,7 @@
name: Jobs name: Jobs
description: Jobs Plugin for the BukkitAPI description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin main: com.gamingmesh.jobs.JobsPlugin
version: 2.51.2 version: 2.51.4
author: phrstbrn author: phrstbrn
softdepend: [Vault] softdepend: [Vault]
commands: commands: