1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 12:35:28 +01:00

Fixed NPE when loading the chunks from database

- Fixed NPE when getting the quests and null
- Removed some deprecated methods
This commit is contained in:
montlikadani 2020-01-08 17:51:40 +01:00
parent 9555d2d79a
commit 1ecffe1895
8 changed files with 18 additions and 58 deletions

View File

@ -12,7 +12,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.stuff.Debug;
public class VersionChecker { public class VersionChecker {
private Jobs plugin; private Jobs plugin;

View File

@ -113,19 +113,8 @@ public class Jobs extends JavaPlugin {
private static Job noneJob = null; private static Job noneJob = null;
private static WeakHashMap<Job, Integer> usedSlots = new WeakHashMap<>(); private static WeakHashMap<Job, Integer> usedSlots = new WeakHashMap<>();
private static HashMap<Integer, Job> jobsIds = new HashMap<>(); private static HashMap<Integer, Job> jobsIds = new HashMap<>();
/**
* Gets the actionbar toggle map
* @deprecated Moved to {@link ToggleBarHandling}
*/
@Deprecated
public static WeakHashMap<String, Boolean> actionbartoggle = new WeakHashMap<>();
/**
* Gets the bossbar toggle map
* @deprecated Moved to {@link ToggleBarHandling}
*/
@Deprecated
public static WeakHashMap<String, Boolean> BossBartoggle = new WeakHashMap<>();
// public static WeakHashMap<String, Double> GlobalBoost = new WeakHashMap<String, Double>(); // public static WeakHashMap<String, Double> GlobalBoost = new WeakHashMap<String, Double>();
private static BufferedEconomy economy = null; private static BufferedEconomy economy = null;
private static PermissionHandler permissionHandler = null; private static PermissionHandler permissionHandler = null;
private static PermissionManager permissionManager = null; private static PermissionManager permissionManager = null;
@ -158,19 +147,6 @@ public class Jobs extends JavaPlugin {
} }
} }
/**
* Gets the {@link #McMMOManager} file
*
* @return McMMO Manager
* @deprecated Use instead {@link #getMcMMOManager()}
*/
@Deprecated
public static McMMOManager getMcMMOlistener() {
if (McMMOManager == null)
McMMOManager = new McMMOManager();
return McMMOManager;
}
public static McMMOManager getMcMMOManager() { public static McMMOManager getMcMMOManager() {
if (McMMOManager == null) if (McMMOManager == null)
McMMOManager = new McMMOManager(); McMMOManager = new McMMOManager();
@ -390,24 +366,6 @@ public class Jobs extends JavaPlugin {
return BBManager; return BBManager;
} }
/**
* Gets the actionbar toggle map
* @deprecated Moved to {@link ToggleBarHandling}
*/
@Deprecated
public static WeakHashMap<String, Boolean> getActionbarToggleList() {
return actionbartoggle;
}
/**
* Gets the bossbar toggle map
* @deprecated Moved to {@link ToggleBarHandling}
*/
@Deprecated
public static WeakHashMap<String, Boolean> getBossBarToggleList() {
return BossBartoggle;
}
/** /**
* Returns schedule manager * Returns schedule manager
* @return the schedule manager * @return the schedule manager
@ -984,6 +942,7 @@ public class Jobs extends JavaPlugin {
e.printStackTrace(); e.printStackTrace();
} }
shutdown(); shutdown();
instance = null;
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully."); consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
setEnabled(false); setEnabled(false);
} }

View File

@ -857,9 +857,7 @@ public class PlayerManager {
} }
public BoostMultiplier getItemBoostNBT(Player player, Job prog) { public BoostMultiplier getItemBoostNBT(Player player, Job prog) {
HashMap<Job, ItemBonusCache> cj = cache.get(player.getUniqueId());
HashMap<Job, ItemBonusCache> cj = cache == null ? new HashMap<Job, ItemBonusCache>() : cache.get(player.getUniqueId());
if (cj == null) { if (cj == null) {
cj = new HashMap<>(); cj = new HashMap<>();
cache.put(player.getUniqueId(), cj); cache.put(player.getUniqueId(), cj);
@ -925,7 +923,6 @@ public class PlayerManager {
Object itemName = Reflections.getNbt(item, JobsItemBoost); Object itemName = Reflections.getNbt(item, JobsItemBoost);
if (itemName == null || itemName.toString().isEmpty()) { if (itemName == null || itemName.toString().isEmpty()) {
// Checking old boost items and converting to new format if needed // Checking old boost items and converting to new format if needed
if (Jobs.getReflections().hasNbt(item, JobsItemBoost)) { if (Jobs.getReflections().hasNbt(item, JobsItemBoost)) {
for (Job one : Jobs.getJobs()) { for (Job one : Jobs.getJobs()) {

View File

@ -168,7 +168,6 @@ public class ConfigManager {
cfg.addComment(pt + ".maxDailyQuests", "You can use the custom player head:", cfg.addComment(pt + ".maxDailyQuests", "You can use the custom player head:",
"Item: player_head", "Item: player_head",
" CustomSkull: Notch", " CustomSkull: Notch",
"", "",
"Defines maximum amount of daily quests player can have from THIS job", "Defines maximum amount of daily quests player can have from THIS job",
"This will not have effect on overall quest amount player will have"); "This will not have effect on overall quest amount player will have");
@ -204,7 +203,7 @@ public class ConfigManager {
cfg.addComment(pt + ".Quests.1.fromLevel", "Defines from which level you want to give option to get this quest", cfg.addComment(pt + ".Quests.1.fromLevel", "Defines from which level you want to give option to get this quest",
"You can use both limitations to have limited quests for particular job level ranges"); "You can use both limitations to have limited quests for particular job level ranges");
cfg.get(pt + ".Quests.1.fromLevel", 3); cfg.get(pt + ".Quests.1.fromLevel", 3);
cfg.addComment(pt + ".Quests.1.toLevel", "Defines to which job level you want to give out this quest.", cfg.addComment(pt + ".Quests.1.toLevel", "Defines to which job level you want to give out this quest.",
"Keep in mind that player will keep quest even if he is over level limit if he got new one while being under", "Keep in mind that player will keep quest even if he is over level limit if he got new one while being under",
"In example: player with level 2 takes quests and levels up to level 5, he still can finish this quest and after next quest reset (check general config file)", "In example: player with level 2 takes quests and levels up to level 5, he still can finish this quest and after next quest reset (check general config file)",
@ -213,7 +212,6 @@ public class ConfigManager {
cfg.save(); cfg.save();
} }
public void reload() throws IOException { public void reload() throws IOException {

View File

@ -17,8 +17,8 @@ public class ExploreChunk {
private boolean updated = false; private boolean updated = false;
public ExploreChunk(int playerId, int x, int z) { public ExploreChunk(int playerId, int x, int z) {
this.x = x; this(x, z);
this.z = z;
this.playerIds.add(playerId); this.playerIds.add(playerId);
} }
@ -70,14 +70,15 @@ public class ExploreChunk {
} }
public Set<Integer> getPlayers() { public Set<Integer> getPlayers() {
return playerIds == null ? new HashSet<>() : playerIds; return playerIds == null ? new HashSet<Integer>() : playerIds;
} }
public String serializeNames() { public String serializeNames() {
String s = "";
if (playerIds == null) if (playerIds == null)
return null; return null;
for (Integer one : this.playerIds) {
String s = "";
for (Integer one : playerIds) {
if (!s.isEmpty()) if (!s.isEmpty())
s += ";"; s += ";";
s += one; s += one;
@ -92,6 +93,10 @@ public class ExploreChunk {
return; return;
} }
if (playerIds == null) {
playerIds = new HashSet<Integer>();
}
List<String> split = Arrays.asList(names.split(";")); List<String> split = Arrays.asList(names.split(";"));
for (String one : split) { for (String one : split) {
try { try {

View File

@ -21,7 +21,7 @@ public class QuestProgression {
} }
public Quest getQuest() { public Quest getQuest() {
return quest.getJob().getQuest(quest.getConfigName()); return quest == null ? null : quest.getJob().getQuest(quest.getConfigName());
} }
public void setQuest(Quest quest) { public void setQuest(Quest quest) {

View File

@ -946,6 +946,7 @@ public class JobsPaymentListener implements Listener {
if (event.getItem() == null || event.getItem().getType() == Material.AIR) if (event.getItem() == null || event.getItem().getType() == Material.AIR)
return; return;
Block block = null; Block block = null;
switch (type.toLowerCase()) { switch (type.toLowerCase()) {
@ -960,6 +961,8 @@ public class JobsPaymentListener implements Listener {
// This should be done in this way to have backwards compatibility // This should be done in this way to have backwards compatibility
block = ((org.bukkit.block.BlastFurnace) event.getDestination().getHolder()).getBlock(); block = ((org.bukkit.block.BlastFurnace) event.getDestination().getHolder()).getBlock();
break; break;
default:
break;
} }
if (block == null) if (block == null)

View File

@ -36,7 +36,6 @@ public class Util {
private static HashMap<UUID, String> jobsEditorMap = new HashMap<>(); private static HashMap<UUID, String> jobsEditorMap = new HashMap<>();
private static HashMap<UUID, String> questsEditorMap = new HashMap<>(); private static HashMap<UUID, String> questsEditorMap = new HashMap<>();
@Deprecated public static List<String> confirmLeave = new ArrayList<>();
public static List<UUID> leaveConfirm = new ArrayList<>(); public static List<UUID> leaveConfirm = new ArrayList<>();
private static HashMap<String, JobsWorld> jobsWorlds = new HashMap<>(); private static HashMap<String, JobsWorld> jobsWorlds = new HashMap<>();