diff --git a/com/gamingmesh/jobs/PermissionHandler.java b/com/gamingmesh/jobs/PermissionHandler.java index 57b6c867..ef029182 100644 --- a/com/gamingmesh/jobs/PermissionHandler.java +++ b/com/gamingmesh/jobs/PermissionHandler.java @@ -20,6 +20,7 @@ package com.gamingmesh.jobs; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; import org.bukkit.World; import org.bukkit.entity.Player; @@ -88,43 +89,34 @@ public class PermissionHandler { for (JobConditions Condition : job.getConditions()) { boolean ok = true; - for (String oneReq : Condition.getRequires()) { - if (oneReq.toLowerCase().contains("j:")) { - String jobName = oneReq.toLowerCase().replace("j:", "").split("-")[0]; - int jobLevel = Integer.valueOf(oneReq.toLowerCase().replace("j:", "").split("-")[1]); - boolean found = false; - for (JobProgression oneJob : jPlayer.getJobProgression()) { - if (oneJob.getJob().getName().equalsIgnoreCase(jobName)) - found = true; - if (oneJob.getJob().getName().equalsIgnoreCase(jobName) && oneJob.getLevel() < jobLevel) { - ok = false; - break; - } - } - if (found == false) - ok = false; - } - if (ok == false) + for (String oneReq : Condition.getRequiredPerm()) { + if (!player.hasPermission(oneReq)) { + ok = false; break; + } + } - if (oneReq.toLowerCase().contains("p:")) { - if (!player.hasPermission(oneReq.replace(":p", ""))) { + for (Entry oneReq : Condition.getRequiredJobs().entrySet()) { + String jobName = oneReq.getKey(); + int jobLevel = oneReq.getValue(); + boolean found = false; + for (JobProgression oneJob : jPlayer.getJobProgression()) { + if (oneJob.getJob().getName().equalsIgnoreCase(jobName)) + found = true; + if (oneJob.getJob().getName().equalsIgnoreCase(jobName) && oneJob.getLevel() < jobLevel) { ok = false; break; } } + if (found == false) + ok = false; } if (!ok) continue; - - for (String one : Condition.getPerform()) { - if (!one.toLowerCase().contains("p:")) - continue; - - String perm = one.toLowerCase().replace("p:", "").split("-")[0]; - boolean node = Boolean.getBoolean(one.toLowerCase().replace("p:", "").split("-")[1]); - + for (Entry one : Condition.getPerformPerm().entrySet()) { + String perm = one.getKey(); + boolean node = one.getValue(); if (node) { permissions.put(perm, true); } else { @@ -136,7 +128,6 @@ public class PermissionHandler { permissions.put(perm, false); } } - } } @@ -162,43 +153,33 @@ public class PermissionHandler { for (JobConditions Condition : prog.getJob().getConditions()) { boolean ok = true; - for (String oneReq : Condition.getRequires()) { - if (oneReq.toLowerCase().contains("j:")) { - String jobName = oneReq.toLowerCase().replace("j:", "").split("-")[0]; - int jobLevel = Integer.valueOf(oneReq.toLowerCase().replace("j:", "").split("-")[1]); - boolean found = false; - for (JobProgression oneJob : jPlayer.getJobProgression()) { - if (oneJob.getJob().getName().equalsIgnoreCase(jobName)) - found = true; - if (oneJob.getJob().getName().equalsIgnoreCase(jobName) && oneJob.getLevel() < jobLevel) { - ok = false; - break; - } - } - if (found == false) - ok = false; - - } - if (ok == false) + for (String oneReq : Condition.getRequiredPerm()) { + if (!player.hasPermission(oneReq)) { + ok = false; break; + } + } - if (oneReq.toLowerCase().contains("p:")) { - if (!player.hasPermission(oneReq.replace("p:", ""))) { + for (Entry oneReq : Condition.getRequiredJobs().entrySet()) { + String jobName = oneReq.getKey(); + int jobLevel = oneReq.getValue(); + boolean found = false; + for (JobProgression oneJob : jPlayer.getJobProgression()) { + if (oneJob.getJob().getName().equalsIgnoreCase(jobName)) + found = true; + if (oneJob.getJob().getName().equalsIgnoreCase(jobName) && oneJob.getLevel() < jobLevel) { ok = false; break; } } + if (found == false) + ok = false; } - if (!ok) continue; - for (String one : Condition.getPerform()) { - if (!one.toLowerCase().contains("p:")) - continue; - String perm = one.toLowerCase().replace("p:", "").split("-")[0]; - String nodeString = one.toLowerCase().replace("p:", "").split("-")[1]; - boolean node = nodeString.equalsIgnoreCase("true") ? true : false; - + for (Entry one : Condition.getPerformPerm().entrySet()) { + String perm = one.getKey(); + boolean node = one.getValue(); if (node) { permissions.put(perm, true); } else { diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 52c46538..517aee45 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -40,7 +40,6 @@ import com.gamingmesh.jobs.api.JobsLevelUpEvent; import com.gamingmesh.jobs.container.BoostMultiplier; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobCommands; -import com.gamingmesh.jobs.container.JobConditions; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; @@ -49,7 +48,6 @@ import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.dao.JobsDAOData; import com.gamingmesh.jobs.economy.PointsData; import com.gamingmesh.jobs.stuff.ChatColor; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.PerformCommands; import com.gamingmesh.jobs.stuff.Perm; @@ -120,8 +118,8 @@ public class PlayerManager { JobsPlayer jPlayer = playersCache.get(player.getName().toLowerCase()); if (jPlayer == null) { jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player); - - JobsPlayer.loadLogFromDao(jPlayer); + if (player.hasPlayedBefore()) + JobsPlayer.loadLogFromDao(jPlayer); playersCache.put(player.getName().toLowerCase(), jPlayer); } @@ -527,56 +525,6 @@ public class PlayerManager { Jobs.getSignUtil().SignUpdate("gtoplist"); } - /** - * Performs command on level up - * @param jPlayer - * @param job - * @param oldLevel - */ - public void CheckConditions(JobsPlayer jPlayer, Job job) { - Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID()); - JobProgression prog = jPlayer.getJobProgression(job); - if (prog == null) - return; - for (JobConditions Condition : job.getConditions()) { - boolean ok = true; - for (String oneReq : Condition.getRequires()) { - if (oneReq.toLowerCase().contains("j:")) { - String jobName = oneReq.toLowerCase().replace("j:", "").split("-")[0]; - int jobLevel = Integer.valueOf(oneReq.toLowerCase().replace("j:", "").split("-")[1]); - boolean found = false; - for (JobProgression oneJob : jPlayer.getJobProgression()) { - if (oneJob.getJob().getName().equalsIgnoreCase(jobName)) - found = true; - if (oneJob.getJob().getName().equalsIgnoreCase(jobName) && oneJob.getLevel() != jobLevel) { - ok = false; - break; - } - } - if (found == false) - ok = false; - } - if (ok = false) - break; - - if (oneReq.toLowerCase().contains("p:")) { - if (!player.hasPermission(oneReq.replace(":p", ""))) { - ok = false; - break; - } - } - } - - if (ok) { - for (String one : Condition.getPerform()) { - if (one.toLowerCase().contains("c:")) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("c:", "").replace("[name]", jPlayer.getUserName())); - } - } - } - } - } - /** * Performs command on level up * @param jPlayer diff --git a/com/gamingmesh/jobs/config/ConfigManager.java b/com/gamingmesh/jobs/config/ConfigManager.java index 48a24bde..5b7d41ed 100644 --- a/com/gamingmesh/jobs/config/ConfigManager.java +++ b/com/gamingmesh/jobs/config/ConfigManager.java @@ -501,25 +501,42 @@ public class ConfigManager { Jobs.getGCManager().setBreederFinder(true); } - // Just to recognize wither skeleton - if (key.equalsIgnoreCase("WitherSkeleton")) { - type = "WitherSkeleton"; + switch (key.toLowerCase()) { + case "skeletonwither": + type = "SkeletonWither"; id = 51; meta = "1"; - } - - // Just to recognize Zombie Villager - if (key.equalsIgnoreCase("ZombieVillager")) { + break; + case "skeletonstray": + type = "SkeletonStray"; + id = 51; + meta = "2"; + break; + case "zombievillager": type = "ZombieVillager"; id = 54; meta = "1"; - } - - // Just to recognize Elder Guardian - if (key.equalsIgnoreCase("ElderGuardian")) { - type = "ElderGuardian"; + break; + case "zombiehusk": + type = "ZombieHusk"; + id = 54; + meta = "2"; + break; + case "horseskeleton": + type = "HorseSkeleton"; + id = 100; + meta = "1"; + break; + case "horsezombie": + type = "HorseZombie"; + id = 100; + meta = "2"; + break; + case "guardianelder": + type = "GuardianElder"; id = 68; meta = "1"; + break; } } else if (actionType == ActionType.ENCHANT && material == null) { diff --git a/com/gamingmesh/jobs/container/ExploreRespond.class b/com/gamingmesh/jobs/container/ExploreRespond.class index e39fefbc..f17b0bc7 100644 Binary files a/com/gamingmesh/jobs/container/ExploreRespond.class and b/com/gamingmesh/jobs/container/ExploreRespond.class differ diff --git a/com/gamingmesh/jobs/container/JobConditions.java b/com/gamingmesh/jobs/container/JobConditions.java index bc0e8bba..dc900aae 100644 --- a/com/gamingmesh/jobs/container/JobConditions.java +++ b/com/gamingmesh/jobs/container/JobConditions.java @@ -18,28 +18,56 @@ package com.gamingmesh.jobs.container; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class JobConditions { private String node; - private List requires; - private List perform; + private List requiresPerm = new ArrayList(); + private HashMap requiresJobs = new HashMap(); + private HashMap performPerm = new HashMap(); public JobConditions(String node, List requires, List perform) { this.node = node; - this.requires = requires; - this.perform = perform; + + for (String one : requires) { + if (one.toLowerCase().contains("j:")) { + String jobName = one.toLowerCase().replace("j:", "").split("-")[0]; + int jobLevel = 0; + try { + jobLevel = Integer.valueOf(one.toLowerCase().replace("j:", "").split("-")[1]); + } catch (Exception e) { + continue; + } + requiresJobs.put(jobName, jobLevel); + } + if (one.toLowerCase().contains("p:")) { + requiresPerm.add(one.replace("p:", "")); + } + } + for (String one : perform) { + if (!one.toLowerCase().contains("p:")) + continue; + String perm = one.toLowerCase().replace("p:", "").split("-")[0]; + boolean n = one.toLowerCase().replace("p:", "").split("-")[1].equalsIgnoreCase("true") ? true : false; + performPerm.put(perm, n); + } } public String getNode() { return node; } - public List getRequires() { - return requires; + public List getRequiredPerm() { + return requiresPerm; } - public List getPerform() { - return perform; + public HashMap getRequiredJobs() { + return requiresJobs; + } + + public HashMap getPerformPerm() { + return performPerm; } } diff --git a/com/gamingmesh/jobs/container/JobsPlayer.java b/com/gamingmesh/jobs/container/JobsPlayer.java index 77b4da7e..fb00a278 100644 --- a/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/com/gamingmesh/jobs/container/JobsPlayer.java @@ -101,6 +101,37 @@ public class JobsPlayer { return jPlayer; } + public static JobsPlayer loadFromDao(JobsDAO dao, Player player) { + + JobsPlayer jPlayer = new JobsPlayer(player.getName(), player); + jPlayer.playerUUID = player.getUniqueId(); + List list = new ArrayList(); + list = dao.getAllJobs(player); +// synchronized (jPlayer.saveLock) { + jPlayer.progression.clear(); + for (JobsDAOData jobdata : list) { + if (Jobs.getJob(jobdata.getJobName()) == null) + continue; + // add the job + Job job = Jobs.getJob(jobdata.getJobName()); + if (job == null) + continue; + + // create the progression object + JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience(), -1, -1, -1); + // calculate the max level + // add the progression level. + jPlayer.progression.add(jobProgression); + + } + jPlayer.reloadMaxExperience(); + jPlayer.reloadLimits(); + jPlayer.setUserId(Jobs.getPlayerManager().getPlayerMap().get(player.getUniqueId().toString()).getID()); + Jobs.getJobsDAO().loadPoints(jPlayer); +// } + return jPlayer; + } + public void setPlayer(Player p) { this.player = p; } @@ -517,7 +548,7 @@ public class JobsPlayer { int numJobs = progression.size(); boolean gotTitle = false; - if (numJobs > 0) + if (numJobs > 0) { for (JobProgression prog : progression) { DisplayMethod method = prog.getJob().getDisplayMethod(); if (method.equals(DisplayMethod.NONE)) @@ -571,7 +602,7 @@ public class JobsPlayer { gotTitle = true; } } - else { + } else { Job nonejob = Jobs.getNoneJob(); if (nonejob != null) { DisplayMethod metod = nonejob.getDisplayMethod(); diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index 3b3efdcf..dfae5762 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -143,12 +143,14 @@ public abstract class JobsDAO { else userData = Jobs.getPlayerManager().getPlayerMap().get(uuid.toString()); + ArrayList jobs = new ArrayList(); + if (userData == null) { - id = recordNewPlayer(playerName, uuid); + recordNewPlayer(playerName, uuid); + return jobs; } else id = userData.getID(); - ArrayList jobs = new ArrayList(); JobsConnection conn = getConnection(); if (conn == null) return jobs; @@ -166,45 +168,32 @@ public abstract class JobsDAO { return jobs; } - public int recordNewPlayer(Player player) { - return recordNewPlayer((OfflinePlayer) player); + public void recordNewPlayer(Player player) { + recordNewPlayer((OfflinePlayer) player); } - public int recordNewPlayer(OfflinePlayer player) { - return recordNewPlayer(player.getName(), player.getUniqueId()); + public void recordNewPlayer(OfflinePlayer player) { + recordNewPlayer(player.getName(), player.getUniqueId()); } - public int recordNewPlayer(String playerName, UUID uuid) { - - int id = -1; - + public void recordNewPlayer(String playerName, UUID uuid) { JobsConnection conn = getConnection(); if (conn == null) - return id; + return; try { PreparedStatement prest = conn.prepareStatement("INSERT INTO `" + prefix + "users` (`player_uuid`, `username`) VALUES (?, ?);"); prest.setString(1, uuid.toString()); prest.setString(2, playerName); prest.executeUpdate(); + ResultSet keys = prest.getGeneratedKeys(); + if (keys.next()) { + int id = keys.getInt(1); + Jobs.getPlayerManager().getPlayerMap().put(uuid.toString(), new PlayerInfo(playerName, id)); + } prest.close(); } catch (SQLException e) { e.printStackTrace(); } - - try { - PreparedStatement prest = conn.prepareStatement("SELECT `id` FROM `" + prefix + "users` WHERE `player_uuid` = ?;"); - prest.setString(1, uuid.toString()); - ResultSet res = prest.executeQuery(); - res.next(); - id = res.getInt("id"); - Jobs.getPlayerManager().getPlayerMap().put(uuid.toString(), new PlayerInfo(playerName, id)); - res.close(); - prest.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - - return id; } /** diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index a59ebef8..e0107005 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -158,27 +158,28 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { + // make sure plugin is enabled if (!plugin.isEnabled()) return; Jobs.getPlayerManager().playerJoin(event.getPlayer()); } - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerJoinMonitor(PlayerJoinEvent event) { - // make sure plugin is enabled - if (!plugin.isEnabled()) - return; - - /* - * We need to recalculate again to check for world permission and revoke permissions - * if we don't have world permission (from some other permission manager). It's - * necessary to call this twice in case somebody is relying on permissions from this - * plugin on entry to the world. - */ - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); - Jobs.getPermissionHandler().recalculatePermissions(jPlayer); - } +// @EventHandler(priority = EventPriority.MONITOR) +// public void onPlayerJoinMonitor(PlayerJoinEvent event) { +// // make sure plugin is enabled +// if (!plugin.isEnabled()) +// return; +// +// /* +// * We need to recalculate again to check for world permission and revoke permissions +// * if we don't have world permission (from some other permission manager). It's +// * necessary to call this twice in case somebody is relying on permissions from this +// * plugin on entry to the world. +// */ +// JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); +// Jobs.getPermissionHandler().recalculatePermissions(jPlayer); +// } @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { @@ -547,7 +548,7 @@ public class JobsListener implements Listener { Map enchants = new HashMap(); try { enchants = iih.getEnchantments(); - } catch (NullPointerException e) { + } catch (Exception e) { return; } if (enchants.isEmpty()) diff --git a/com/gamingmesh/jobs/nmsUtil/v1_10.java b/com/gamingmesh/jobs/nmsUtil/v1_10.java index 6869573d..c78324bd 100644 --- a/com/gamingmesh/jobs/nmsUtil/v1_10.java +++ b/com/gamingmesh/jobs/nmsUtil/v1_10.java @@ -14,6 +14,7 @@ import org.bukkit.entity.Skeleton; import org.bukkit.entity.Zombie; import org.bukkit.entity.Horse.Variant; import org.bukkit.entity.Skeleton.SkeletonType; +import org.bukkit.entity.Villager.Profession; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.inventory.ItemStack; @@ -52,8 +53,10 @@ public class v1_10 implements NMS { break; case ZOMBIE: Zombie zombie = (Zombie) entity; - if (zombie.isVillager()) + if (zombie.isVillager() && zombie.getVillagerProfession() != Profession.HUSK) return "ZombieVillager"; + if (zombie.isVillager() && zombie.getVillagerProfession() == Profession.HUSK) + return "ZombieHusk"; break; default: break; diff --git a/com/gamingmesh/jobs/nmsUtil/v1_9.class b/com/gamingmesh/jobs/nmsUtil/v1_9.class index fcca0d67..a74b5716 100644 Binary files a/com/gamingmesh/jobs/nmsUtil/v1_9.class and b/com/gamingmesh/jobs/nmsUtil/v1_9.class differ diff --git a/plugin.yml b/plugin.yml index 85432adf..dec5cdf1 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.JobsPlugin -version: 3.4.0 +version: 3.4.2 author: phrstbrn depend: [Vault] softdepend: [CoreProtect, MythicMobs, McMMO]