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

@ -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,15 +42,15 @@ 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) {
// synchronized (players) {
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
if (jPlayer == null) {
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
@ -63,7 +61,7 @@ public class PlayerManager {
jPlayer.reloadHonorific();
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
return;
}
// }
}
/**
@ -71,7 +69,7 @@ public class PlayerManager {
* @param playername
*/
public void playerQuit(Player player) {
synchronized (players) {
// synchronized (players) {
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
@ -84,7 +82,7 @@ public class PlayerManager {
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) {
// synchronized (players) {
list = new ArrayList<JobsPlayer>(players.values());
}
// }
for (JobsPlayer jPlayer : list) {
jPlayer.save(dao);
}
synchronized (players) {
// synchronized (players) {
Iterator<JobsPlayer> iter = players.values().iterator();
while (iter.hasNext()) {
JobsPlayer jPlayer = iter.next();
synchronized (jPlayer.saveLock) {
// 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,7 +163,7 @@ public class PlayerManager {
* @param job
*/
public void joinJob(JobsPlayer jPlayer, Job job) {
synchronized (jPlayer.saveLock) {
// synchronized (jPlayer.saveLock) {
if (jPlayer.isInJob(job))
return;
// 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("gtoplist");
job.updateTotalPlayers();
}
// }
}
/**
@ -190,7 +192,7 @@ public class PlayerManager {
* @param job
*/
public void leaveJob(JobsPlayer jPlayer, Job job) {
synchronized (jPlayer.saveLock) {
// synchronized (jPlayer.saveLock) {
if (!jPlayer.isInJob(job))
return;
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("gtoplist");
job.updateTotalPlayers();
}
// }
}
/**
@ -220,7 +222,7 @@ public class PlayerManager {
* @param jPlayer
*/
public void leaveAllJobs(JobsPlayer jPlayer) {
synchronized (jPlayer.saveLock) {
// synchronized (jPlayer.saveLock) {
for (JobProgression job : jPlayer.getJobProgression()) {
Jobs.getJobsDAO().quitJob(jPlayer, job.getJob());
PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob());
@ -232,7 +234,7 @@ public class PlayerManager {
}
jPlayer.leaveAllJobs();
}
// }
}
/**
@ -242,7 +244,7 @@ public class PlayerManager {
* @param newjob - the new job
*/
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
synchronized (jPlayer.saveLock) {
// synchronized (jPlayer.saveLock) {
if (!jPlayer.transferJob(oldjob, newjob, jPlayer))
return;
@ -252,7 +254,7 @@ public class PlayerManager {
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) {
// 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");
}
// }
}
/**
@ -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) {
// 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,7 +295,7 @@ public class PlayerManager {
* @param experience - experience gained
*/
public void addExperience(JobsPlayer jPlayer, Job job, double experience) {
synchronized (jPlayer.saveLock) {
// synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
@ -304,7 +306,7 @@ public class PlayerManager {
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
}
// }
}
/**
@ -314,7 +316,7 @@ public class PlayerManager {
* @param experience - experience gained
*/
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
synchronized (jPlayer.saveLock) {
// synchronized (jPlayer.saveLock) {
JobProgression prog = jPlayer.getJobProgression(job);
if (prog == null)
return;
@ -323,7 +325,7 @@ public class PlayerManager {
jPlayer.save(Jobs.getJobsDAO());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName());
com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist");
}
// }
}
/**
@ -558,7 +560,7 @@ public class PlayerManager {
* Perform reload
*/
public void reload() {
synchronized (players) {
// synchronized (players) {
for (JobsPlayer jPlayer : players.values()) {
for (JobProgression progression : jPlayer.getJobProgression()) {
String jobName = progression.getJob().getName();
@ -572,6 +574,6 @@ public class PlayerManager {
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) {
// synchronized (saveLock) {
if (!isSaved()) {
dao.save(this);
dao.saveLog(this);
setSaved(true);
}
}
// }
}
/**

View File

@ -81,7 +81,10 @@ public abstract class JobsDAO {
checkUpdate4();
checkUpdate5();
version = 5;
if (version <= 5)
checkUpdate6();
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

@ -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,7 +258,6 @@ public class JobsListener implements Listener {
if (!(block.getState() instanceof Sign))
return;
Player player = (Player) event.getPlayer();
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);
}
}
return;
}
}, 1);
}

View File

@ -1,25 +1,20 @@
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) {
for (OfflinePlayer one : Bukkit.getOfflinePlayers()) {
if (one == null)
continue;
map.put(one.getName().toLowerCase(), one);
@ -27,8 +22,6 @@ public class OfflinePlayerList {
}
return;
}
});
}
public static OfflinePlayer getPlayer(UUID uuid) {
if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData)

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: