1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +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

@ -30,36 +30,36 @@ import com.gamingmesh.jobs.economy.BlackholeEconomy;
import com.gamingmesh.jobs.economy.VaultEconomy;
public class HookEconomyTask implements Runnable {
private JobsPlugin plugin;
private JobsPlugin plugin;
public HookEconomyTask(JobsPlugin plugin) {
this.plugin = plugin;
}
public HookEconomyTask(JobsPlugin plugin) {
this.plugin = plugin;
}
public void run() {
Plugin eco = Bukkit.getServer().getPluginManager().getPlugin("Vault");
if (eco != null) {
RegisteredServiceProvider<Economy> provider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (provider != null) {
Economy economy = provider.getProvider();
if (economy != null) {
Jobs.setEconomy(plugin, new VaultEconomy(economy));
String message = ChatColor.translateAlternateColorCodes('&', "&2[" + plugin.getDescription().getName() + "] Successfully linked with Vault.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
return;
}
}
public void run() {
Plugin eco = Bukkit.getServer().getPluginManager().getPlugin("Vault");
if (eco != null) {
RegisteredServiceProvider<Economy> provider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (provider != null) {
Economy economy = provider.getProvider();
if (economy != null) {
Jobs.setEconomy(plugin, new VaultEconomy(economy));
String message = ChatColor.translateAlternateColorCodes('&', "&2[" + plugin.getDescription().getName() + "] Successfully linked with Vault.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
return;
}
// no Vault found
Jobs.setEconomy(plugin, new BlackholeEconomy());
Bukkit.getServer().getLogger().severe("==================== " + plugin.getDescription().getName() + " ====================");
Bukkit.getServer().getLogger().severe("Vault is required by this plugin for economy support!");
Bukkit.getServer().getLogger().severe("Please install Vault first!");
Bukkit.getServer().getLogger().severe("You can find the latest version here:");
Bukkit.getServer().getLogger().severe("http://dev.bukkit.org/server-mods/vault/");
Bukkit.getServer().getLogger().severe("==============================================");
}
}
// no Vault found
Jobs.setEconomy(plugin, new BlackholeEconomy());
Bukkit.getServer().getLogger().severe("==================== " + plugin.getDescription().getName() + " ====================");
Bukkit.getServer().getLogger().severe("Vault is required by this plugin for economy support!");
Bukkit.getServer().getLogger().severe("Please install Vault first!");
Bukkit.getServer().getLogger().severe("You can find the latest version here:");
Bukkit.getServer().getLogger().severe("http://dev.bukkit.org/server-mods/vault/");
Bukkit.getServer().getLogger().severe("==============================================");
}
}

View File

@ -19,10 +19,8 @@
package com.gamingmesh.jobs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@ -44,26 +42,26 @@ import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.PerformCommands;
public class PlayerManager {
private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>());
//private Map<String, JobsPlayer> players = new HashMap<String, JobsPlayer>();
// private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>());
private ConcurrentHashMap<String, JobsPlayer> players = new ConcurrentHashMap<String, JobsPlayer>();
/**
* Handles join of new player
* @param playername
*/
public void playerJoin(Player player) {
synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
JobsPlayer.loadLogFromDao(jPlayer);
players.put(player.getName().toLowerCase(), jPlayer);
}
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
// synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
JobsPlayer.loadLogFromDao(jPlayer);
players.put(player.getName().toLowerCase(), jPlayer);
}
jPlayer.onConnect();
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
// }
}
/**
@ -71,20 +69,20 @@ public class PlayerManager {
* @param playername
*/
public void playerQuit(Player player) {
synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.save(Jobs.getJobsDAO());
jPlayer.onDisconnect();
}
} else {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.onDisconnect();
}
// synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.save(Jobs.getJobsDAO());
jPlayer.onDisconnect();
}
} else {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.onDisconnect();
}
}
// }
}
/**
@ -101,25 +99,25 @@ public class PlayerManager {
* 3) Garbage collect the real list to remove any offline players with saved data
*/
ArrayList<JobsPlayer> list = null;
synchronized (players) {
list = new ArrayList<JobsPlayer>(players.values());
}
// synchronized (players) {
list = new ArrayList<JobsPlayer>(players.values());
// }
for (JobsPlayer jPlayer : list) {
jPlayer.save(dao);
}
synchronized (players) {
Iterator<JobsPlayer> iter = players.values().iterator();
while (iter.hasNext()) {
JobsPlayer jPlayer = iter.next();
synchronized (jPlayer.saveLock) {
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
iter.remove();
}
}
// synchronized (players) {
Iterator<JobsPlayer> iter = players.values().iterator();
while (iter.hasNext()) {
JobsPlayer jPlayer = iter.next();
// synchronized (jPlayer.saveLock) {
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
iter.remove();
}
// }
}
// }
}
/**
@ -128,7 +126,9 @@ public class PlayerManager {
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayer(Player player) {
// synchronized (players) {
return players.get(player.getName().toLowerCase());
// }
}
/**
@ -137,7 +137,9 @@ public class PlayerManager {
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayer(String playerName) {
// synchronized (players) {
return players.get(playerName.toLowerCase());
// }
}
/**
@ -161,27 +163,27 @@ public class PlayerManager {
* @param job
*/
public void joinJob(JobsPlayer jPlayer, Job job) {
synchronized (jPlayer.saveLock) {
if (jPlayer.isInJob(job))
return;
// let the user join the job
if (!jPlayer.joinJob(job, jPlayer))
return;
// synchronized (jPlayer.saveLock) {
if (jPlayer.isInJob(job))
return;
// let the user join the job
if (!jPlayer.joinJob(job, jPlayer))
return;
// JobsJoin event
JobsJoinEvent jobsjoinevent = new JobsJoinEvent(jPlayer, job);
Bukkit.getServer().getPluginManager().callEvent(jobsjoinevent);
// If event is canceled, dont do anything
if (jobsjoinevent.isCancelled())
return;
// JobsJoin event
JobsJoinEvent jobsjoinevent = new JobsJoinEvent(jPlayer, job);
Bukkit.getServer().getPluginManager().callEvent(jobsjoinevent);
// If event is canceled, dont do anything
if (jobsjoinevent.isCancelled())
return;
Jobs.getJobsDAO().joinJob(jPlayer, job);
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
Jobs.takeSlot(job);
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.updateTotalPlayers();
}
Jobs.getJobsDAO().joinJob(jPlayer, job);
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
Jobs.takeSlot(job);
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.updateTotalPlayers();
// }
}
/**
@ -190,29 +192,29 @@ public class PlayerManager {
* @param job
*/
public void leaveJob(JobsPlayer jPlayer, Job job) {
synchronized (jPlayer.saveLock) {
if (!jPlayer.isInJob(job))
return;
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
// let the user leave the job
if (!jPlayer.leaveJob(job))
return;
// synchronized (jPlayer.saveLock) {
if (!jPlayer.isInJob(job))
return;
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
// let the user leave the job
if (!jPlayer.leaveJob(job))
return;
// JobsJoin event
JobsLeaveEvent jobsleaveevent = new JobsLeaveEvent(jPlayer, job);
Bukkit.getServer().getPluginManager().callEvent(jobsleaveevent);
// If event is canceled, dont do anything
if (jobsleaveevent.isCancelled())
return;
// JobsJoin event
JobsLeaveEvent jobsleaveevent = new JobsLeaveEvent(jPlayer, job);
Bukkit.getServer().getPluginManager().callEvent(jobsleaveevent);
// If event is canceled, dont do anything
if (jobsleaveevent.isCancelled())
return;
Jobs.getJobsDAO().quitJob(jPlayer, job);
PerformCommands.PerformCommandsOnLeave(jPlayer, job);
Jobs.leaveSlot(job);
Jobs.getJobsDAO().quitJob(jPlayer, job);
PerformCommands.PerformCommandsOnLeave(jPlayer, job);
Jobs.leaveSlot(job);
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.updateTotalPlayers();
}
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.updateTotalPlayers();
// }
}
/**
@ -220,19 +222,19 @@ public class PlayerManager {
* @param jPlayer
*/
public void leaveAllJobs(JobsPlayer jPlayer) {
synchronized (jPlayer.saveLock) {
for (JobProgression job : jPlayer.getJobProgression()) {
Jobs.getJobsDAO().quitJob(jPlayer, job.getJob());
PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob());
Jobs.leaveSlot(job.getJob());
// synchronized (jPlayer.saveLock) {
for (JobProgression job : jPlayer.getJobProgression()) {
Jobs.getJobsDAO().quitJob(jPlayer, job.getJob());
PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob());
Jobs.leaveSlot(job.getJob());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getJob().getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.getJob().updateTotalPlayers();
}
jPlayer.leaveAllJobs();
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getJob().getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
job.getJob().updateTotalPlayers();
}
jPlayer.leaveAllJobs();
// }
}
/**
@ -242,17 +244,17 @@ public class PlayerManager {
* @param newjob - the new job
*/
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
synchronized (jPlayer.saveLock) {
if (!jPlayer.transferJob(oldjob, newjob, jPlayer))
return;
// synchronized (jPlayer.saveLock) {
if (!jPlayer.transferJob(oldjob, newjob, jPlayer))
return;
JobsDAO dao = Jobs.getJobsDAO();
dao.quitJob(jPlayer, oldjob);
oldjob.updateTotalPlayers();
dao.joinJob(jPlayer, newjob);
newjob.updateTotalPlayers();
jPlayer.save(dao);
}
JobsDAO dao = Jobs.getJobsDAO();
dao.quitJob(jPlayer, oldjob);
oldjob.updateTotalPlayers();
dao.joinJob(jPlayer, newjob);
newjob.updateTotalPlayers();
jPlayer.save(dao);
// }
}
/**
@ -262,13 +264,13 @@ public class PlayerManager {
* @param levels - number of levels to promote
*/
public void promoteJob(JobsPlayer jPlayer, Job job, int levels) {
synchronized (jPlayer.saveLock) {
jPlayer.promoteJob(job, levels, jPlayer);
jPlayer.save(Jobs.getJobsDAO());
// synchronized (jPlayer.saveLock) {
jPlayer.promoteJob(job, levels, jPlayer);
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
}
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
// }
}
/**
@ -278,12 +280,12 @@ public class PlayerManager {
* @param levels - number of levels to demote
*/
public void demoteJob(JobsPlayer jPlayer, Job job, int levels) {
synchronized (jPlayer.saveLock) {
jPlayer.demoteJob(job, levels);
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
}
// synchronized (jPlayer.saveLock) {
jPlayer.demoteJob(job, levels);
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
// }
}
/**
@ -293,18 +295,18 @@ public class PlayerManager {
* @param experience - experience gained
*/
public void addExperience(JobsPlayer jPlayer, Job job, double experience) {
synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
int oldLevel = prog.getLevel();
if (prog.addExperience(experience))
performLevelUp(jPlayer, job, oldLevel);
// synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
int oldLevel = prog.getLevel();
if (prog.addExperience(experience))
performLevelUp(jPlayer, job, oldLevel);
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
}
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
// }
}
/**
@ -314,16 +316,16 @@ public class PlayerManager {
* @param experience - experience gained
*/
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
prog.addExperience(-experience);
// synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
prog.addExperience(-experience);
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
}
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
// }
}
/**
@ -558,20 +560,20 @@ public class PlayerManager {
* Perform reload
*/
public void reload() {
synchronized (players) {
for (JobsPlayer jPlayer : players.values()) {
for (JobProgression progression : jPlayer.getJobProgression()) {
String jobName = progression.getJob().getName();
Job job = Jobs.getJob(jobName);
if (job != null) {
progression.setJob(job);
}
}
if (jPlayer.isOnline()) {
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
// synchronized (players) {
for (JobsPlayer jPlayer : players.values()) {
for (JobProgression progression : jPlayer.getJobProgression()) {
String jobName = progression.getJob().getName();
Job job = Jobs.getJob(jobName);
if (job != null) {
progression.setJob(job);
}
}
if (jPlayer.isOnline()) {
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
}
}
// }
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -185,11 +185,11 @@ public class JobsDAOMySQL extends JobsDAO {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size());
i = 0;
}
OfflinePlayer offPlayer = OfflinePlayerList.getPlayer(names);
if (offPlayer == null)
continue;
pst2.setBytes(1, UUIDUtil.toBytes(offPlayer.getUniqueId()));
pst2.setString(2, names);
pst2.execute();
@ -316,8 +316,18 @@ public class JobsDAOMySQL extends JobsDAO {
try {
if (rows == 0)
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 {
}
}
@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 {
if (rows == 0)
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 {
}
}
@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.BlockBreakEvent;
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.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -45,6 +48,8 @@ import org.bukkit.plugin.PluginManager;
import com.gamingmesh.jobs.Jobs;
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.config.ConfigManager;
import com.gamingmesh.jobs.container.Job;
@ -60,100 +65,100 @@ public class JobsListener implements Listener {
this.plugin = plugin;
}
// @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
// public void onGuiRightClick(InventoryClickEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0)
// return;
//
// Player player = (Player) event.getWhoClicked();
//
// if (!Gui.GuiTools.GuiList.containsKey(player.getName()))
// return;
//
// if (event.getClick() != ClickType.RIGHT)
// return;
//
// event.setCancelled(true);
//
// GuiInfoList joblist = Gui.GuiTools.GuiList.get(player.getName());
//
// if (joblist.isJobInfo())
// return;
//
// int slot = event.getRawSlot();
//
// if (slot < joblist.getJobList().size()) {
// Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName());
// player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents());
// }
// }
//
// @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
// public void onGuiLeftClick(InventoryClickEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0)
// return;
//
// Player player = (Player) event.getWhoClicked();
//
// if (!Gui.GuiTools.GuiList.containsKey(player.getName()))
// return;
//
// event.setCancelled(true);
//
// if (event.getClick() != ClickType.LEFT)
// return;
//
// GuiInfoList joblist = Gui.GuiTools.GuiList.get(player.getName());
//
// if (joblist.isJobInfo())
// return;
//
// int slot = event.getRawSlot();
//
// if (slot < joblist.getJobList().size()) {
// player.closeInventory();
// player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot)));
// }
// }
//
// @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
// public void onGuiLeftSubClick(InventoryClickEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0)
// return;
//
// Player player = (Player) event.getWhoClicked();
//
// if (!Gui.GuiTools.GuiList.containsKey(player.getName()))
// return;
//
// event.setCancelled(true);
//
// if (event.getClick() != ClickType.LEFT)
// return;
//
// GuiInfoList joblist = Gui.GuiTools.GuiList.get(player.getName());
//
// if (!joblist.isJobInfo())
// return;
//
// int slot = event.getRawSlot();
//
// if (slot == joblist.getbackButton()) {
// player.closeInventory();
// player.openInventory(GuiTools.CreateJobsGUI(player));
// }
// }
//
// @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
// public void onGuiClose(InventoryCloseEvent event) {
// if (Gui.GuiTools.GuiList.size() == 0)
// return;
//
// Player player = (Player) event.getPlayer();
//
// if (Gui.GuiTools.GuiList.containsKey(player.getName()))
// Gui.GuiTools.GuiList.remove(player.getName());
// }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onGuiRightClick(InventoryClickEvent event) {
if (GuiTools.GuiList.size() == 0)
return;
Player player = (Player) event.getWhoClicked();
if (!GuiTools.GuiList.containsKey(player.getName()))
return;
if (event.getClick() != ClickType.RIGHT)
return;
event.setCancelled(true);
GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
if (joblist.isJobInfo())
return;
int slot = event.getRawSlot();
if (slot < joblist.getJobList().size()) {
Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName());
player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents());
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onGuiLeftClick(InventoryClickEvent event) {
if (GuiTools.GuiList.size() == 0)
return;
Player player = (Player) event.getWhoClicked();
if (!GuiTools.GuiList.containsKey(player.getName()))
return;
event.setCancelled(true);
if (event.getClick() != ClickType.LEFT)
return;
GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
if (joblist.isJobInfo())
return;
int slot = event.getRawSlot();
if (slot < joblist.getJobList().size()) {
player.closeInventory();
player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot)));
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onGuiLeftSubClick(InventoryClickEvent event) {
if (GuiTools.GuiList.size() == 0)
return;
Player player = (Player) event.getWhoClicked();
if (!GuiTools.GuiList.containsKey(player.getName()))
return;
event.setCancelled(true);
if (event.getClick() != ClickType.LEFT)
return;
GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
if (!joblist.isJobInfo())
return;
int slot = event.getRawSlot();
if (slot == joblist.getbackButton()) {
player.closeInventory();
player.openInventory(GuiTools.CreateJobsGUI(player));
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onGuiClose(InventoryCloseEvent event) {
if (GuiTools.GuiList.size() == 0)
return;
Player player = (Player) event.getPlayer();
if (GuiTools.GuiList.containsKey(player.getName()))
GuiTools.GuiList.remove(player.getName());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) {
@ -253,9 +258,8 @@ public class JobsListener implements Listener {
if (!(block.getState() instanceof Sign))
return;
Player player = (Player) event.getPlayer();
Sign sign = (Sign) block.getState();
String FirstLine = sign.getLine(0);
if (FirstLine.equalsIgnoreCase(Language.getMessage("signs.topline")))
@ -264,7 +268,7 @@ public class JobsListener implements Listener {
player.sendMessage(Language.getMessage("signs.cantdestroy"));
return;
}
Location loc = block.getLocation();
for (com.gamingmesh.jobs.Signs.Sign one : SignUtil.Signs.GetAllSigns()) {

View File

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

View File

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

View File

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