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

We don't need to check by offline player and properly update cache on

player logout
This commit is contained in:
Zrips 2016-09-21 17:18:08 +03:00
parent 558f775b2b
commit 81a02dbbe0
21 changed files with 67 additions and 122 deletions

View File

@ -1,6 +1,6 @@
/HookEconomyTask.class
/Jobs.class
/JobsPlugin.class
/Jobs.class
/PermissionHandler.class
/PlayerManager.class
/Jobs$1.class

View File

@ -28,7 +28,6 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -141,14 +140,14 @@ public class PlayerManager {
* @param playername
*/
public void playerQuit(Player player) {
JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase());
playersCache.put(player.getName().toLowerCase(), jPlayer);
if (Jobs.getGCManager().saveOnDisconnect()) {
JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.save();
jPlayer.onDisconnect();
}
} else {
JobsPlayer jPlayer = this.players.get(player.getName().toLowerCase());
if (jPlayer != null) {
jPlayer.onDisconnect();
}
@ -196,53 +195,10 @@ public class PlayerManager {
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayer(String playerName) {
return this.playersCache.get(playerName.toLowerCase());
}
public JobsPlayer getJobsPlayerOffline(OfflinePlayer player) {
return getJobsPlayerOffline(player.getName());
}
/**
* Get the player job info for specific player
* @param player - the player who's job you're getting
* @return the player job info of the player
*/
public JobsPlayer getJobsPlayerOffline(String playerName) {
JobsPlayer jPlayer = this.playersCache.get(playerName.toLowerCase());
JobsPlayer jPlayer = this.players.get(playerName.toLowerCase());
if (jPlayer != null)
return jPlayer;
Entry<String, PlayerInfo> info = getPlayerInfoByName(playerName);
if (info == null)
return null;
if (info.getValue().getName() == null)
return null;
jPlayer = new JobsPlayer(info.getValue().getName(), null);
jPlayer.setPlayerUUID(UUID.fromString(info.getKey()));
jPlayer.setUserId(info.getValue().getID());
List<JobsDAOData> list = Jobs.getJobsDAO().getAllJobs(info.getValue().getName(), UUID.fromString(info.getKey()));
for (JobsDAOData jobdata : list) {
if (Jobs.getJob(jobdata.getJobName()) == null)
continue;
Job job = Jobs.getJob(jobdata.getJobName());
if (job == null)
continue;
JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience());
jPlayer.progression.add(jobProgression);
jPlayer.reloadMaxExperience();
jPlayer.reloadLimits();
}
Jobs.getJobsDAO().loadPoints(jPlayer);
jPlayer.loadLogFromDao();
return jPlayer;
return this.playersCache.get(playerName.toLowerCase());
}
/**

View File

@ -46,3 +46,4 @@
/blockinfo.class
/test.class
/purge.class
/saveall.class

View File

@ -2,8 +2,6 @@ package com.gamingmesh.jobs.commands.list;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -24,9 +22,7 @@ public class archive implements Cmd {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission"));
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
} else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);

View File

@ -1,7 +1,6 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -22,22 +21,26 @@ public class demote implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
try {
// check if player already has the job
if (jPlayer.isInJob(job)) {
Integer levelsLost = Integer.parseInt(args[2]);
Jobs.getPlayerManager().demoteJob(jPlayer, job, levelsLost);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
if (player != null) {
String message = Jobs.getLanguage().getMessage("command.demote.output.target",
"%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE,

View File

@ -19,8 +19,6 @@ public class editpoints implements Cmd {
}
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[1]);
if (jPlayer == null)
jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(args[1]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[1]));

View File

@ -22,15 +22,19 @@ public class employ implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
if (jPlayer.isInJob(job)) {
// already in job message
String message = ChatColor.RED + Jobs.getLanguage().getMessage("command.employ.error.alreadyin", "%jobname%", job.getChatColor() + job.getName()
@ -41,7 +45,7 @@ public class employ implements Cmd {
try {
// check if player already has the job
Jobs.getPlayerManager().joinJob(jPlayer, job);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null)
player.sendMessage(Jobs.getLanguage().getMessage("command.employ.output.target", "%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE));

View File

@ -22,21 +22,19 @@ public class fire implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
if (jPlayer == null){
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
if (!jPlayer.isInJob(job)) {
String message = ChatColor.RED + Jobs.getLanguage().getMessage("command.fire.error.nojob", "%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
sender.sendMessage(message);
@ -44,7 +42,7 @@ public class fire implements Cmd {
}
try {
Jobs.getPlayerManager().leaveJob(jPlayer, job);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null) {
String message = Jobs.getLanguage().getMessage("command.fire.output.target", "%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
player.sendMessage(message);

View File

@ -2,8 +2,6 @@ package com.gamingmesh.jobs.commands.list;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -24,10 +22,11 @@ public class fireall implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
List<JobProgression> jobs = jPlayer.getJobProgression();
if (jobs.size() == 0) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.fireall.error.nojobs"));
@ -36,7 +35,7 @@ public class fireall implements Cmd {
try {
Jobs.getPlayerManager().leaveAllJobs(jPlayer);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.fireall.output.target"));
}

View File

@ -47,9 +47,6 @@ public class glog implements Cmd {
continue;
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(name);
if (JPlayer == null) {
JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(name);
}
if (JPlayer == null)
continue;

View File

@ -1,8 +1,6 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -23,9 +21,7 @@ public class grantxp implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
Job job = Jobs.getJob(args[1]);
if (job == null) {
@ -43,11 +39,17 @@ public class grantxp implements Cmd {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.admin.error"));
return true;
}
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
// check if player already has the job
if (jPlayer.isInJob(job)) {
Jobs.getPlayerManager().addExperience(jPlayer, job, xpGained);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null) {
String message = Jobs.getLanguage().getMessage("command.grantxp.output.target",
"%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE,

View File

@ -40,8 +40,6 @@ public class log implements Cmd {
return true;
}
JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (JPlayer == null)
JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(args[0]);
}
if (JPlayer == null) {

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import com.gamingmesh.jobs.Jobs;
@ -22,9 +20,7 @@ public class playerinfo implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
String jobName = args[1];
Job job = Jobs.getJob(jobName);

View File

@ -28,8 +28,6 @@ public class points implements Cmd {
return true;
}
jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null)
jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(args[0]);
} else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
}

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -22,22 +20,24 @@ public class promote implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
Job job = Jobs.getJob(args[1]);
if (job == null) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
return true;
}
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
try {
// check if player already has the job
if (jPlayer.isInJob(job)) {
Integer levelsGained = Integer.parseInt(args[2]);
Jobs.getPlayerManager().promoteJob(jPlayer, job, levelsGained);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.promote.output.target",
"%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE,

View File

@ -1,8 +1,6 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -23,9 +21,12 @@ public class removexp implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
Job job = Jobs.getJob(args[1]);
if (job == null) {
@ -47,7 +48,7 @@ public class removexp implements Cmd {
if (jPlayer.isInJob(job)) {
Jobs.getPlayerManager().removeExperience(jPlayer, job, xpLost);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.removexp.output.target",
"%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE,

View File

@ -22,8 +22,6 @@ public class stats implements Cmd {
return true;
}
jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null)
jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(args[0]);
} else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
}

View File

@ -1,8 +1,6 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -23,10 +21,11 @@ public class transfer implements Cmd {
return true;
}
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (jPlayer == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfoByPlayer", "%playername%", args[0]));
return true;
}
Job oldjob = Jobs.getJob(args[1]);
Job newjob = Jobs.getJob(args[2]);
if (oldjob == null) {
@ -41,7 +40,7 @@ public class transfer implements Cmd {
if (jPlayer.isInJob(oldjob) && !jPlayer.isInJob(newjob)) {
Jobs.getPlayerManager().transferJob(jPlayer, oldjob, newjob);
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
Player player = jPlayer.getPlayer();
if (player != null) {
String message = Jobs.getLanguage().getMessage("command.transfer.output.target",
"%oldjobname%", oldjob.getChatColor() + oldjob.getName() + ChatColor.WHITE,

View File

@ -36,3 +36,4 @@
/BoostType.class
/McmmoSkill.class
/FastPayment.class
/TempJobProgression.class

View File

@ -118,9 +118,9 @@ public class JobsPlayer {
* @return the player
*/
public Player getPlayer() {
if (this.player != null)
return this.player;
return Bukkit.getPlayer(this.playerUUID);
if (this.playerUUID != null)
this.player = Bukkit.getPlayer(this.playerUUID);
return this.player;
}
/**

View File

@ -1,7 +1,7 @@
name: Jobs
description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.Jobs
version: 3.5.6
version: 3.5.7
author: phrstbrn
depend: [Vault]
softdepend: [CoreProtect, MythicMobs, McMMO]