diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 7e13162e..fda0cd5c 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -43,6 +43,7 @@ import org.bukkit.inventory.meta.FireworkMeta; import com.gamingmesh.jobs.CMILib.ItemReflection; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; +import com.gamingmesh.jobs.Signs.SignTopType; import com.gamingmesh.jobs.api.JobsJoinEvent; import com.gamingmesh.jobs.api.JobsLeaveEvent; import com.gamingmesh.jobs.api.JobsLevelUpEvent; @@ -366,8 +367,8 @@ public class PlayerManager { Jobs.getJobsDAO().joinJob(jPlayer, jPlayer.getJobProgression(job)); PerformCommands.PerformCommandsOnJoin(jPlayer, job); Jobs.takeSlot(job); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); job.updateTotalPlayers(); // } } @@ -398,8 +399,8 @@ public class PlayerManager { PerformCommands.PerformCommandsOnLeave(jPlayer, job); Jobs.leaveSlot(job); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); job.updateTotalPlayers(); return true; // } @@ -450,8 +451,8 @@ public class PlayerManager { jPlayer.promoteJob(job, levels); jPlayer.save(); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); // } } @@ -465,8 +466,8 @@ public class PlayerManager { // synchronized (jPlayer.saveLock) { jPlayer.demoteJob(job, levels); jPlayer.save(); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); // } } @@ -482,12 +483,13 @@ public class PlayerManager { if (prog == null) return; int oldLevel = prog.getLevel(); - if (prog.addExperience(experience)) + if (prog.addExperience(experience)) { performLevelUp(jPlayer, job, oldLevel); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); + } jPlayer.save(); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); // } } @@ -505,8 +507,8 @@ public class PlayerManager { prog.addExperience(-experience); jPlayer.save(); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); // } } @@ -549,8 +551,8 @@ public class PlayerManager { jPlayer.reloadHonorific(); Jobs.getPermissionHandler().recalculatePermissions(jPlayer); performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); return; } @@ -618,7 +620,7 @@ public class PlayerManager { Color c2 = Util.getColor(r2i); FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1) - .withFade(c2).with(type).trail(r.nextBoolean()).build(); + .withFade(c2).with(type).trail(r.nextBoolean()).build(); fm.addEffect(effect); int rp = r.nextInt(2) + 1; @@ -740,8 +742,8 @@ public class PlayerManager { jPlayer.reloadHonorific(); Jobs.getPermissionHandler().recalculatePermissions(jPlayer); performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel); - Jobs.getSignUtil().SignUpdate(job.getName()); - Jobs.getSignUtil().SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job); + Jobs.getSignUtil().SignUpdate(SignTopType.gtoplist); } /** diff --git a/src/main/java/com/gamingmesh/jobs/Signs/Sign.java b/src/main/java/com/gamingmesh/jobs/Signs/Sign.java deleted file mode 100644 index 006316ea..00000000 --- a/src/main/java/com/gamingmesh/jobs/Signs/Sign.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.gamingmesh.jobs.Signs; - -public class Sign { - - private String World = null; - private double x = 0.01; - private double y = 0.01; - private double z = 0.01; - private int Number = 0; - private String JobName = null; - private boolean special = false; - - public void setSpecial(boolean special) { - this.special = special; - } - - public boolean isSpecial() { - return special; - } - - public void setJobName(String JobName) { - this.JobName = JobName; - } - - public String getJobName() { - return JobName; - } - - public void setWorld(String World) { - this.World = World; - } - - public String getWorld() { - return World; - } - - public void setX(double x) { - this.x = x; - } - - public double getX() { - return x; - } - - public void setY(double y) { - this.y = y; - } - - public double getY() { - return y; - } - - public void setZ(double z) { - this.z = z; - } - - public double getZ() { - return z; - } - - public void setNumber(int Number) { - this.Number = Number; - } - - public int getNumber() { - return Number; - } -} diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignInfo.java b/src/main/java/com/gamingmesh/jobs/Signs/SignInfo.java index 07e29c79..a06e2bce 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignInfo.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignInfo.java @@ -5,21 +5,21 @@ import java.util.List; public class SignInfo { - private List AllSigns = new ArrayList<>(); + private List AllSigns = new ArrayList<>(); - public void setAllSigns(List AllSigns) { + public void setAllSigns(List AllSigns) { this.AllSigns = AllSigns; } - public List GetAllSigns() { + public List GetAllSigns() { return AllSigns; } - public void removeSign(Sign sign) { + public void removeSign(jobsSign sign) { this.AllSigns.remove(sign); } - public void addSign(Sign sign) { + public void addSign(jobsSign sign) { this.AllSigns.add(sign); } } diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignTopType.java b/src/main/java/com/gamingmesh/jobs/Signs/SignTopType.java new file mode 100644 index 00000000..d41581ee --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignTopType.java @@ -0,0 +1,13 @@ +package com.gamingmesh.jobs.Signs; + +public enum SignTopType { + toplist, gtoplist, questtoplist; + public static SignTopType getType(String type) { + for (SignTopType one : SignTopType.values()) { + if (one.toString().equalsIgnoreCase(type)) { + return one; + } + } + return null; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index 0e34b570..a2c2bdcf 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -5,11 +5,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Skull; @@ -21,19 +21,58 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.config.CommentedYamlConfiguration; +import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; +import com.gamingmesh.jobs.stuff.Debug; public class SignUtil { - private SignInfo Signs = new SignInfo(); + private HashMap> SignsByType = new HashMap>(); + private HashMap SignsByLocation = new HashMap(); private Jobs plugin; public SignUtil(Jobs plugin) { this.plugin = plugin; } - public SignInfo getSigns() { - return Signs; + public HashMap> getSigns() { + return SignsByType; + } + + public boolean removeSign(Location loc) { + jobsSign jSign = SignsByLocation.remove(jobsSign.locToBlockString(loc)); + if (jSign == null) + return false; + + HashMap sub = SignsByType.get(jSign.getIdentifier().toLowerCase()); + if (sub != null) { + sub.remove(jSign.locToBlockString()); + } + return true; + } + + public jobsSign getSign(Location loc) { + if (loc == null) + return null; + return SignsByLocation.get(jobsSign.locToBlockString(loc)); + } + + public void addSign(jobsSign jSign) { + if (jSign == null) + return; + SignsByLocation.put(jSign.locToBlockString(), jSign); + + HashMap old = SignsByType.get(jSign.getIdentifier().toLowerCase()); + if (old == null) { + old = new HashMap(); + SignsByType.put(jSign.getIdentifier().toLowerCase(), old); + } + + String loc = jSign.locToBlockString(); + if (loc == null) { + return; + } + old.put(loc, jSign); } // Sign file @@ -42,7 +81,8 @@ public class SignUtil { if (!Jobs.getGCManager().SignsEnabled) return; - Signs.GetAllSigns().clear(); + SignsByType.clear(); + SignsByLocation.clear(); File file = new File(Jobs.getFolder(), "Signs.yml"); YamlConfiguration f = YamlConfiguration.loadConfiguration(file); @@ -56,16 +96,37 @@ public class SignUtil { for (String category : categoriesList) { ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category); - com.gamingmesh.jobs.Signs.Sign newTemp = new com.gamingmesh.jobs.Signs.Sign(); - newTemp.setWorld(NameSection.getString("World")); - newTemp.setX(NameSection.getDouble("X")); - newTemp.setY(NameSection.getDouble("Y")); - newTemp.setZ(NameSection.getDouble("Z")); + jobsSign newTemp = new jobsSign(); + if (NameSection.isString("World")) { + newTemp.setWorldName(NameSection.getString("World")); + newTemp.setX((int) NameSection.getDouble("X")); + newTemp.setY((int) NameSection.getDouble("Y")); + newTemp.setZ((int) NameSection.getDouble("Z")); + } else { + newTemp.setLoc(NameSection.getString("Loc")); + } + if (NameSection.isString("Type")) + newTemp.setType(SignTopType.getType(NameSection.getString("Type"))); + newTemp.setNumber(NameSection.getInt("Number")); - newTemp.setJobName(NameSection.getString("JobName")); + if (NameSection.isString("JobName")) + newTemp.setJobName(NameSection.getString("JobName")); newTemp.setSpecial(NameSection.getBoolean("Special")); - Signs.addSign(newTemp); + + HashMap old = SignsByType.get(newTemp.getJobName().toLowerCase()); + if (old == null) { + old = new HashMap(); + SignsByType.put(newTemp.getJobName().toLowerCase(), old); + } + String loc = newTemp.locToBlockString(); + if (loc == null) { + Jobs.consoleMsg("&cFailed to load (" + category + ") sign location"); + continue; + } + old.put(loc, newTemp); + SignsByLocation.put(loc, newTemp); } + Jobs.consoleMsg("&e[Jobs] Loaded " + SignsByLocation.size() + " top list signs"); return; } @@ -83,16 +144,15 @@ public class SignUtil { conf.createSection("Signs"); int i = 0; - for (com.gamingmesh.jobs.Signs.Sign one : Signs.GetAllSigns()) { + for (Entry one : SignsByLocation.entrySet()) { + jobsSign sign = one.getValue(); ++i; String path = "Signs." + i; - writer.set(path + ".World", one.getWorld()); - writer.set(path + ".X", one.getX()); - writer.set(path + ".Y", one.getY()); - writer.set(path + ".Z", one.getZ()); - writer.set(path + ".Number", one.getNumber()); - writer.set(path + ".JobName", one.getJobName()); - writer.set(path + ".Special", one.isSpecial()); + writer.set(path + ".Loc", sign.locToBlockString()); + writer.set(path + ".Number", sign.getNumber()); + writer.set(path + ".Type", sign.getType().toString()); + writer.set(path + ".JobName", sign.getJobName()); + writer.set(path + ".Special", sign.isSpecial()); } try { @@ -103,7 +163,15 @@ public class SignUtil { return; } - public boolean SignUpdate(String JobName) { + public boolean SignUpdate(Job job) { + return SignUpdate(job, SignTopType.toplist); + } + + public boolean SignUpdate(SignTopType type) { + return SignUpdate(null, type); + } + + public boolean SignUpdate(Job job, SignTopType type) { if (!Jobs.getGCManager().SignsEnabled) return true; @@ -111,115 +179,134 @@ public class SignUtil { List PlayerList = new ArrayList<>(); - if (JobName.contains("gtoplist")) - PlayerList = Jobs.getJobsDAO().getGlobalTopList(0); + if (type == null && job == null) + return false; + + if (type == null && job != null) + type = SignTopType.toplist; + + if (type == null) + type = SignTopType.toplist; HashMap> temp = new HashMap<>(); - for (com.gamingmesh.jobs.Signs.Sign one : new ArrayList(Signs.GetAllSigns())) { - String SignJobName = one.getJobName(); + String JobNameOrType = jobsSign.getIdentifier(job, type); - if (!JobName.contains(SignJobName)) + HashMap signs = this.SignsByType.get(JobNameOrType.toLowerCase()); + + if (signs == null) + return false; + + switch (type) { + case toplist: + break; + case gtoplist: + PlayerList = Jobs.getJobsDAO().getGlobalTopList(0); + break; + case questtoplist: + PlayerList = Jobs.getJobsDAO().getQuestTopList(0); + break; + default: + break; + } + + boolean save = false; + for (Entry one : (new HashMap(signs)).entrySet()) { + jobsSign jSign = one.getValue(); + String SignJobName = jSign.getJobName(); + Location loc = jSign.getLocation(); + if (loc == null) continue; - World world = Bukkit.getWorld(one.getWorld()); - if (world == null) - continue; + int number = jSign.getNumber() - 1; - double SignsX = one.getX(); - double SignsY = one.getY(); - double SignsZ = one.getZ(); - int number = one.getNumber() - 1; - - if (!JobName.contains("gtoplist")) { + switch (type) { + case toplist: PlayerList = temp.get(SignJobName); if (PlayerList == null) { PlayerList = Jobs.getJobsDAO().toplist(SignJobName); temp.put(SignJobName, PlayerList); } + break; } if (PlayerList.isEmpty()) continue; - Location nloc = new Location(world, SignsX, SignsY, SignsZ); - Block block = nloc.getBlock(); + Block block = loc.getBlock(); if (!(block.getState() instanceof org.bukkit.block.Sign)) { - Signs.GetAllSigns().remove(one); - saveSigns(); + + HashMap tt = this.SignsByType.get(JobNameOrType.toLowerCase()); + if (tt != null) { + tt.remove(jSign.locToBlockString()); + } + this.SignsByLocation.remove(jSign.locToBlockString()); + save = true; continue; } org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState(); - if (!one.isSpecial()) { + if (!jSign.isSpecial()) { for (int i = 0; i < 4; i++) { - if (i + number + 1 >= PlayerList.size()) + if (i + number >= PlayerList.size()) break; String PlayerName = PlayerList.get(i + number).getPlayerName(); - if (PlayerName != null && PlayerName.length() > 15) { - String PlayerNameStrip = PlayerName.split("(?<=\\G.{15})")[0]; - PlayerName = PlayerNameStrip + "~"; - } - if (PlayerName == null) PlayerName = "Unknown"; - String line = Jobs.getLanguage().getMessage("signs.List"); - line = line.replace("[number]", String.valueOf(i + number + 1)); - line = line.replace("[player]", PlayerName); - line = line.replace("[level]", String.valueOf(PlayerList.get(i + number).getLevel())); + if (PlayerName.length() > 15) { + PlayerName = PlayerName.split("(?<=\\G.{15})")[0] + "~"; + } + String line = ""; + switch (type) { + case toplist: + case gtoplist: + line = Jobs.getLanguage().getMessage("signs.List", "[number]", i + number + 1, "[player]", PlayerName, "[level]", PlayerList.get(i + number).getLevel()); + break; + case questtoplist: + line = Jobs.getLanguage().getMessage("signs.questList", "[number]", i + number + 1, "[player]", PlayerName, "[quests]", PlayerList.get(i + number).getLevel()); + break; + default: + break; + } sign.setLine(i, line); } sign.update(); if (!UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse)) timelapse--; } else { - if (one.getNumber() > PlayerList.size()) + if (jSign.getNumber() > PlayerList.size()) return true; - TopList pl = PlayerList.get(one.getNumber() - 1); + TopList pl = PlayerList.get(jSign.getNumber() - 1); String PlayerName = pl.getPlayerName(); - if (PlayerName != null && PlayerName.length() > 15) { - String PlayerNameStrip = PlayerName.split("(?<=\\G.{15})")[0]; - PlayerName = PlayerNameStrip + "~"; - } if (PlayerName == null) PlayerName = "Unknown"; - String line1 = Jobs.getLanguage().getMessage("signs.SpecialList.p" + one.getNumber(), - "[number]", one.getNumber() + number + 1, - "[player]", PlayerName, - "[level]", pl.getLevel(), - "[job]", JobName); + if (PlayerName.length() > 15) { + PlayerName = PlayerName.split("(?<=\\G.{15})")[0] + "~"; + } - sign.setLine(0, line1); + int no = jSign.getNumber() + number + 1; + sign.setLine(0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, PlayerName, pl.getLevel(), SignJobName)); + sign.setLine(1, translateSignLine("signs.SpecialList.name", no, PlayerName, pl.getLevel(), SignJobName)); - line1 = Jobs.getLanguage().getMessage("signs.SpecialList.name", - "[number]", one.getNumber() + number + 1, - "[player]", PlayerName, - "[level]", pl.getLevel(), - "[job]", JobName); + switch (type) { + case toplist: + case gtoplist: + sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.level", "[number]", no, "[player]", PlayerName, "[level]", pl.getLevel(), "[job]", SignJobName)); + break; + case questtoplist: + sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", PlayerName, "[quests]", pl.getLevel(), "[job]", SignJobName)); + break; + default: + break; + } - sign.setLine(1, line1); - - line1 = Jobs.getLanguage().getMessage("signs.SpecialList.level", - "[number]", one.getNumber() + number + 1, - "[player]", PlayerName, - "[level]", pl.getLevel(), - "[job]", JobName); - - sign.setLine(2, line1); - - line1 = Jobs.getLanguage().getMessage("signs.SpecialList.bottom", - "[number]", one.getNumber() + number + 1, - "[player]", PlayerName, - "[level]", pl.getLevel(), - "[job]", JobName); - - sign.setLine(3, line1); + sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, PlayerName, pl.getLevel(), SignJobName)); sign.update(); if (!UpdateHead(sign, pl.getPlayerName(), timelapse)) @@ -229,7 +316,19 @@ public class SignUtil { timelapse++; } + if (save) + saveSigns(); + return true; + + } + + private static String translateSignLine(String path, int number, String playerName, int level, String jobname) { + return Jobs.getLanguage().getMessage(path, + "[number]", number, + "[player]", playerName, + "[level]", level, + "[job]", jobname); } public boolean UpdateHead(final org.bukkit.block.Sign sign, final String Playername, int timelapse) { diff --git a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java new file mode 100644 index 00000000..a24a16c8 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java @@ -0,0 +1,164 @@ +package com.gamingmesh.jobs.Signs; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.stuff.Util; + +public class jobsSign { + + private String worldName; + private Integer x; + private Integer y; + private Integer z; + private World world; + private Location loc; + private Integer number; + private String jobName; + private Boolean special; + private SignTopType type; + + public void setSpecial(boolean special) { + this.special = special; + } + + public boolean isSpecial() { + return special == null ? false : special; + } + + public void setJobName(String JobName) { + this.jobName = JobName; + } + + public String getJobName() { + return jobName; + } + + public void setWorldName(String World) { + this.worldName = World; + } + + public String getWorldName() { + return worldName; + } + + public void setX(int x) { + this.x = x; + } + + public double getX() { + return x; + } + + public void setY(int y) { + this.y = y; + } + + public double getY() { + return y; + } + + public void setZ(int z) { + this.z = z; + } + + public double getZ() { + return z; + } + + public Location getLocation() { + if (loc != null) + return loc; + if (worldName == null) + return null; + world = Bukkit.getWorld(worldName); + if (world == null) + return null; + loc = new Location(world, x, y, z); + return loc; + } + + public void setNumber(int Number) { + this.number = Number; + } + + public int getNumber() { + return number; + } + + public String locToBlockString() { + return worldName + ";" + x + ";" + y + ";" + z; + } + + public static String locToBlockString(Location loc) { + if (loc == null) + return ""; + return loc.getWorld().getName() + ";" + loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); + } + + public void setLoc(Location loc) { + if (loc == null) + return; + this.worldName = loc.getWorld().getName(); + this.x = loc.getBlockX(); + this.y = loc.getBlockY(); + this.z = loc.getBlockZ(); + this.world = loc.getWorld(); + this.loc = loc; + } + + public void setLoc(String string) { + + if (!string.contains(";")) + return; + String[] split = string.replace(",", ".").split(";"); + + Integer x = 0; + Integer y = 0; + Integer z = 0; + + if (split.length > 0) + try { + x = Integer.parseInt(split[1]); + } catch (Exception e) { + return; + } + + if (split.length > 1) + try { + y = Integer.parseInt(split[2]); + } catch (Exception e) { + return; + } + + if (split.length > 2) + try { + z = Integer.parseInt(split[3]); + } catch (Exception e) { + return; + } + + World world = Util.getWorld(split[0]); + if (world == null) + return; + this.setLoc(new Location(world, x, y, z)); + } + + public SignTopType getType() { + return type == null ? SignTopType.toplist : type; + } + + public void setType(SignTopType type) { + this.type = type; + } + + public String getIdentifier() { + return this.jobName != null ? this.jobName : this.getType().toString(); + } + + public static String getIdentifier(Job job, SignTopType type) { + return job != null ? job.getName() : type == null ? SignTopType.toplist.toString() : type.toString(); + } +} diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java b/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java index 4f462689..03490449 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java @@ -3,6 +3,7 @@ package com.gamingmesh.jobs.commands.list; import org.bukkit.command.CommandSender; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.Signs.SignTopType; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; @@ -13,7 +14,7 @@ public class signupdate implements Cmd { @JobCommand(2700) public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { if (!Jobs.getGCManager().SignsEnabled) - return true; + return true; if (args.length != 1) { Jobs.getCommandManager().sendUsage(sender, "signupdate"); @@ -22,14 +23,14 @@ public class signupdate implements Cmd { Job oldjob = Jobs.getJob(args[0]); - if (oldjob == null && !args[0].equalsIgnoreCase("gtoplist")) { + SignTopType type = SignTopType.getType(args[0]); + + if (type == SignTopType.toplist && oldjob == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } - if (!args[0].equalsIgnoreCase("gtoplist") && oldjob != null) - Jobs.getSignUtil().SignUpdate(oldjob.getName()); - else - Jobs.getSignUtil().SignUpdate("gtoplist"); + + Jobs.getSignUtil().SignUpdate(oldjob, type); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index 19eaaa5c..be04c260 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -649,6 +649,7 @@ public class LanguageManager { c.get("message.crafting.fullinventory", "&cYour inventory is full!"); c.get("signs.List", "&0[number].&8[player]&7:&4[level]"); + c.get("signs.questList", "&0[number].&8[player]&7:&4[quests]"); c.get("signs.SpecialList.p1", "&b** &8First &b**"); c.get("signs.SpecialList.p2", "&b** &8Second &b**"); c.get("signs.SpecialList.p3", "&b** &8Third &b**"); @@ -661,6 +662,7 @@ public class LanguageManager { c.get("signs.SpecialList.p10", "&b** &8Tenth &b**"); c.get("signs.SpecialList.name", "&9[player]"); c.get("signs.SpecialList.level", "&8[level] level"); + c.get("signs.SpecialList.quests", "&8[quests] quests"); c.get("signs.SpecialList.bottom", "&b************"); c.get("signs.cantcreate", "&4You can't create this sign!"); c.get("signs.cantdestroy", "&4You can't destroy this sign!"); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 7087b17c..66b0cedb 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -29,6 +29,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.Signs.SignTopType; import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.resources.jfep.Parser; @@ -1059,7 +1060,8 @@ public class JobsPlayer { this.doneQuests = doneQuests; } - public void addDoneQuest() { + public void addDoneQuest() { + Jobs.getSignUtil().SignUpdate(SignTopType.questtoplist); this.doneQuests++; } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 905231de..6282b689 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1132,8 +1132,8 @@ public abstract class JobsDAO { } /** - * Get all jobs from archive by player - * @param player - targeted player + * Get player list by total job level + * @param start - starting entry * @return info - information about jobs */ public List getGlobalTopList(int start) { @@ -1171,6 +1171,47 @@ public abstract class JobsDAO { return names; } + /** + * Get players by quests done + * @param start - starting entry + * @param size - max count of entries + * @return info - information about jobs + */ + public List getQuestTopList(int start) { + JobsConnection conn = getConnection(); + + List names = new ArrayList<>(); + + if (conn == null) + return names; + PreparedStatement prest = null; + ResultSet res = null; + try { + prest = conn.prepareStatement("SELECT `id`, `player_uuid`, `donequests` FROM `" + prefix + + "users` ORDER BY `donequests` DESC, LOWER(seen) DESC LIMIT " + start + ", " + (start + Jobs.getGCManager().JobsTopAmount + 1) + ";"); + + res = prest.executeQuery(); + + while (res.next()) { + PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(res.getInt("id")); + if (info == null) + continue; + if (info.getName() == null) + continue; + TopList top = new TopList(info, res.getInt("donequests"), 0); + names.add(top); + if (names.size() >= Jobs.getGCManager().JobsTopAmount) + break; + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + close(res); + close(prest); + } + return names; + } + public PlayerInfo loadPlayerData(UUID uuid) { PlayerInfo pInfo = null; JobsConnection conn = getConnection(); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 378a7f97..b7d6ad7c 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -74,6 +74,9 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.Gui.GuiInfoList; +import com.gamingmesh.jobs.Signs.SignTopType; +import com.gamingmesh.jobs.Signs.SignUtil; +import com.gamingmesh.jobs.Signs.jobsSign; import com.gamingmesh.jobs.api.JobsAreaSelectionEvent; import com.gamingmesh.jobs.api.JobsChunkChangeEvent; import com.gamingmesh.jobs.container.ArmorTypes; @@ -112,8 +115,7 @@ public class JobsListener implements Listener { if (msg == null) return; - Bukkit.getServer().getScheduler().runTask(plugin, () -> - player.performCommand(msg + event.getMessage())); + Bukkit.getServer().getScheduler().runTask(plugin, () -> player.performCommand(msg + event.getMessage())); event.setCancelled(true); } @@ -250,14 +252,14 @@ public class JobsListener implements Listener { Inventory inv = Jobs.getGUIManager().CreateJobsSubGUI(player, job); Inventory top = player.getOpenInventory().getTopInventory(); // if (top.getSize() == Jobs.getGCManager().getJobsGUIRows() * 9) - top.setContents(inv.getContents()); + top.setContents(inv.getContents()); } } else if (joblist.isJobInfo()) { if (slot == joblist.getbackButton()) { Inventory inv = Jobs.getGUIManager().CreateJobsGUI(player); Inventory top = player.getOpenInventory().getTopInventory(); // if (top.getSize() == Jobs.getGCManager().getJobsGUIRows() * 9) - top.setContents(inv.getContents()); + top.setContents(inv.getContents()); } } else if (!Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.RIGHT || Jobs.getGCManager().JobsGUISwitcheButtons && event.getClick() == ClickType.LEFT) { @@ -409,27 +411,17 @@ public class JobsListener implements Listener { } } - Location loc = block.getLocation(); + jobsSign jSign = Jobs.getSignUtil().getSign(block.getLocation()); + if (jSign == null) + return; - for (com.gamingmesh.jobs.Signs.Sign one : Jobs.getSignUtil().getSigns().GetAllSigns()) { - - if (one.getX() != loc.getBlockX()) - continue; - if (one.getY() != loc.getBlockY()) - continue; - if (one.getZ() != loc.getBlockZ()) - continue; - - if (!player.hasPermission("jobs.command.signs")) { - event.setCancelled(true); - player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); - return; - } - - Jobs.getSignUtil().getSigns().removeSign(one); - Jobs.getSignUtil().saveSigns(); - break; + if (!player.hasPermission("jobs.command.signs")) { + event.setCancelled(true); + player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); + return; } + if (Jobs.getSignUtil().removeSign(block.getLocation())) + Jobs.getSignUtil().saveSigns(); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -449,10 +441,12 @@ public class JobsListener implements Listener { final String signtype = ChatColor.stripColor(event.getLine(1)); + SignTopType type = SignTopType.getType(signtype); + if (!ChatColor.stripColor(event.getLine(0)).equalsIgnoreCase("[Jobs]")) return; - if (!(signtype.contains("toplist") || signtype.contains("gtoplist"))) + if (type == null) return; Player player = event.getPlayer(); @@ -470,7 +464,7 @@ public class JobsListener implements Listener { final Job job = Jobs.getJob(jobname); - if (job == null && !signtype.contains("gtoplist")) { + if (type == SignTopType.toplist && job == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); return; } @@ -490,33 +484,27 @@ public class JobsListener implements Listener { return; } - com.gamingmesh.jobs.Signs.Sign signInfo = new com.gamingmesh.jobs.Signs.Sign(); - com.gamingmesh.jobs.Signs.SignUtil signUtil = Jobs.getSignUtil(); + jobsSign signInfo = new jobsSign(); + SignUtil signUtil = Jobs.getSignUtil(); Location loc = sign.getLocation(); - + signInfo.setLoc(loc); signInfo.setNumber(Number); - signInfo.setWorld(loc.getWorld().getName()); - signInfo.setX(loc.getX()); - signInfo.setY(loc.getY()); - signInfo.setZ(loc.getZ()); - if (!signtype.contains("gtoplist") && job != null) + + if (job != null) signInfo.setJobName(job.getName()); - else - signInfo.setJobName("gtoplist"); + signInfo.setType(type); + signInfo.setSpecial(special); - signUtil.getSigns().addSign(signInfo); + signUtil.addSign(signInfo); signUtil.saveSigns(); event.setCancelled(true); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { - if (!signtype.contains("gtoplist") && job != null) - signUtil.SignUpdate(job.getName()); - else - signUtil.SignUpdate("gtoplist"); + signUtil.SignUpdate(job, type); return; } }, 1L); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index f6110f61..1f08856e 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -6,8 +6,10 @@ import java.util.Iterator; import java.util.List; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.CreatureSpawner; @@ -53,6 +55,25 @@ public class Util { return is; } + public static World getWorld(String name) { + World w = null; + w = Bukkit.getWorld(name); + + if (w != null) + return w; + + name = name.replace("_", "").replace(".", "").replace("-", ""); + + for (World one : Bukkit.getWorlds()) { + String n = one.getName().replace("_", "").replace(".", "").replace("-", ""); + if (!n.equalsIgnoreCase(name)) + continue; + return one; + } + + return null; + } + public static String firstToUpperCase(String name) { return name.toLowerCase().replace("_", " ").substring(0, 1).toUpperCase() + name.toLowerCase().replace("_", " ").substring(1); }