From 19f917507216afea616cc153ccbc04daf066b690 Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 6 Jan 2016 15:40:27 +0200 Subject: [PATCH] Code cleaning and preventing self killing income --- com/gamingmesh/jobs/Jobs.java | 58 ++- com/gamingmesh/jobs/JobsPlugin.java | 16 +- com/gamingmesh/jobs/PlayerManager.java | 32 +- com/gamingmesh/jobs/Signs/SignUtil.java | 474 +++++++++--------- .../jobs/commands/JobsCommands.java | 16 +- .../jobs/config/JobsConfiguration.java | 8 +- com/gamingmesh/jobs/dao/JobsDAO.java | 9 +- com/gamingmesh/jobs/i18n/Language.java | 99 ++-- .../jobs/listeners/JobsListener.java | 23 +- .../jobs/listeners/JobsPaymentListener.java | 6 + com/gamingmesh/jobs/stuff/ActionBar.java | 309 ++++++------ com/gamingmesh/jobs/stuff/Debug.java | 33 +- com/gamingmesh/jobs/stuff/Loging.java | 112 ++--- com/gamingmesh/jobs/stuff/Scboard.java | 15 +- com/gamingmesh/jobs/stuff/ScheduleUtil.java | 282 ++++++----- plugin.yml | 2 +- 16 files changed, 803 insertions(+), 691 deletions(-) diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index f17873ae..adf56376 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -33,6 +33,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import com.gamingmesh.jobs.Signs.SignUtil; import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.container.ActionInfo; import com.gamingmesh.jobs.container.Job; @@ -47,12 +48,19 @@ import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.JobsClassLoader; import com.gamingmesh.jobs.stuff.Loging; +import com.gamingmesh.jobs.stuff.Scboard; +import com.gamingmesh.jobs.stuff.ScheduleUtil; import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; public class Jobs { public static Jobs instance = new Jobs(); +// public static JobsPlugin plugin = new JobsPlugin(); private static PlayerManager pManager = new PlayerManager(); + private static Language lManager = new Language(); + private static SignUtil signManager = new SignUtil(); + private static Scboard scboardManager = new Scboard(); + private static ScheduleUtil scheduleManager = new ScheduleUtil(); private static Logger pLogger; private static File dataFolder; @@ -83,6 +91,54 @@ public class Jobs { return pManager; } + /** + * Returns schedule manager + * @return the schedule manager + */ + public static ScheduleUtil getSchedule() { + return scheduleManager; + } + + public static void setSchedule(JobsPlugin plugin) { + scheduleManager = new ScheduleUtil(plugin); + } + + /** + * Returns scoreboard manager + * @return the scoreboard manager + */ + public static Scboard getScboard() { + return scboardManager; + } + + public static void setScboard(JobsPlugin plugin) { + scboardManager = new Scboard(plugin); + } + + /** + * Returns sign manager + * @return the sign manager + */ + public static SignUtil getSignUtil() { + return signManager; + } + + public static void setSignUtil(JobsPlugin plugin) { + signManager = new SignUtil(plugin); + } + + /** + * Returns language manager + * @return the language manager + */ + public static Language getLanguage() { + return lManager; + } + + public static void setLanguage(JobsPlugin plugin) { + lManager = new Language(plugin); + } + /** * Sets the plugin logger */ @@ -207,7 +263,7 @@ public class Jobs { } ConfigManager.getJobsConfiguration().reload(); - Language.reload(ConfigManager.getJobsConfiguration().getLocale()); + Jobs.getLanguage().reload(ConfigManager.getJobsConfiguration().getLocale()); ConfigManager.getJobConfig().reload(); usedSlots.clear(); for (Job job : jobs) { diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java index 5f092a85..14e464a1 100644 --- a/com/gamingmesh/jobs/JobsPlugin.java +++ b/com/gamingmesh/jobs/JobsPlugin.java @@ -27,7 +27,6 @@ import net.elseland.xikage.MythicMobs.API.MythicMobsAPI; import org.bukkit.Bukkit; import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.ChatColor; @@ -42,12 +41,10 @@ import com.gamingmesh.jobs.listeners.McMMOlistener; import com.gamingmesh.jobs.listeners.MythicMobsListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.stuff.OfflinePlayerList; -import com.gamingmesh.jobs.stuff.ScheduleUtil; import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.config.YmlMaker; public class JobsPlugin extends JavaPlugin { - public static Plugin instance; public static CoreProtectAPI CPAPI; public static MythicMobsAPI MMAPI; public static boolean CPPresent = false; @@ -96,7 +93,6 @@ public class JobsPlugin extends JavaPlugin { this.setEnabled(false); } - instance = this; OfflinePlayerList.fillList(); YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); jobConfig.saveDefaultConfig(); @@ -109,6 +105,11 @@ public class JobsPlugin extends JavaPlugin { Jobs.setPermissionHandler(new PermissionHandler(this)); + Jobs.setSignUtil(this); + Jobs.setScboard(this); + Jobs.setSchedule(this); + Jobs.setLanguage(this); + Jobs.setPluginLogger(getLogger()); Jobs.setDataFolder(getDataFolder()); @@ -116,7 +117,7 @@ public class JobsPlugin extends JavaPlugin { ConfigManager.registerJobsConfiguration(new JobsConfiguration(this)); ConfigManager.registerJobConfig(new JobConfig(this)); - getCommand("jobs").setExecutor(new JobsCommands()); + getCommand("jobs").setExecutor(new JobsCommands(this)); this.getCommand("jobs").setTabCompleter(new TabComplete()); @@ -154,12 +155,13 @@ public class JobsPlugin extends JavaPlugin { // all loaded properly. if (ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) - ScheduleUtil.scheduler(); - ScheduleUtil.DateUpdater(); + Jobs.getSchedule().scheduler(); + Jobs.getSchedule().DateUpdater(); String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] &6Plugin has been enabled succesfully."); ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); console.sendMessage(message); + Jobs.getLanguage().reload(ConfigManager.getJobsConfiguration().getLocale()); } @Override diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index c4973a12..7a1fe156 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -180,8 +180,8 @@ public class PlayerManager { Jobs.getJobsDAO().joinJob(jPlayer, job); PerformCommands.PerformCommandsOnJoin(jPlayer, job); Jobs.takeSlot(job); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); job.updateTotalPlayers(); // } } @@ -211,8 +211,8 @@ public class PlayerManager { PerformCommands.PerformCommandsOnLeave(jPlayer, job); Jobs.leaveSlot(job); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); job.updateTotalPlayers(); // } } @@ -228,8 +228,8 @@ public class PlayerManager { PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob()); Jobs.leaveSlot(job.getJob()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getJob().getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getJob().getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); job.getJob().updateTotalPlayers(); } @@ -268,8 +268,8 @@ public class PlayerManager { jPlayer.promoteJob(job, levels, jPlayer); jPlayer.save(Jobs.getJobsDAO()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); // } } @@ -283,8 +283,8 @@ public class PlayerManager { // 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"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); // } } @@ -304,8 +304,8 @@ public class PlayerManager { performLevelUp(jPlayer, job, oldLevel); jPlayer.save(Jobs.getJobsDAO()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); // } } @@ -323,8 +323,8 @@ public class PlayerManager { prog.addExperience(-experience); jPlayer.save(Jobs.getJobsDAO()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); // } } @@ -419,8 +419,8 @@ public class PlayerManager { jPlayer.reloadHonorific(); Jobs.getPermissionHandler().recalculatePermissions(jPlayer); performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate("gtoplist"); } /** diff --git a/com/gamingmesh/jobs/Signs/SignUtil.java b/com/gamingmesh/jobs/Signs/SignUtil.java index d5d18e68..9471dc50 100644 --- a/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/com/gamingmesh/jobs/Signs/SignUtil.java @@ -1,231 +1,243 @@ -package com.gamingmesh.jobs.Signs; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.Skull; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.JobsPlugin; -import com.gamingmesh.jobs.config.CommentedYamlConfiguration; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.container.TopList; -import com.gamingmesh.jobs.i18n.Language; - -public class SignUtil { - - public static SignInfo Signs = new SignInfo(); - - // Sign file - public static void LoadSigns() { - Thread threadd = new Thread() { - public void run() { - - Signs.GetAllSigns().clear(); - File file = new File(JobsPlugin.instance.getDataFolder(), "Signs.yml"); - YamlConfiguration f = YamlConfiguration.loadConfiguration(file); - - if (!f.isConfigurationSection("Signs")) - return; - - ConfigurationSection ConfCategory = f.getConfigurationSection("Signs"); - ArrayList categoriesList = new ArrayList(ConfCategory.getKeys(false)); - if (categoriesList.size() == 0) - return; - for (String category : categoriesList) { - ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category); - com.gamingmesh.jobs.Signs.Sign newTemp = new com.gamingmesh.jobs.Signs.Sign(); - newTemp.setCategory(Integer.valueOf(category)); - newTemp.setWorld(NameSection.getString("World")); - newTemp.setX(NameSection.getDouble("X")); - newTemp.setY(NameSection.getDouble("Y")); - newTemp.setZ(NameSection.getDouble("Z")); - newTemp.setNumber(NameSection.getInt("Number")); - newTemp.setJobName(NameSection.getString("JobName")); - newTemp.setSpecial(NameSection.getBoolean("Special")); - Signs.addSign(newTemp); - } - return; - } - }; - threadd.start(); - } - - // Signs save file - public static void saveSigns() { - - Thread threadd = new Thread() { - public void run() { - File f = new File(JobsPlugin.instance.getDataFolder(), "Signs.yml"); - YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); - - CommentedYamlConfiguration writer = new CommentedYamlConfiguration(); - conf.options().copyDefaults(true); - - writer.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!"); - - if (!conf.isConfigurationSection("Signs")) - conf.createSection("Signs"); - - for (com.gamingmesh.jobs.Signs.Sign one : Signs.GetAllSigns()) { - String path = "Signs." + String.valueOf(one.GetCategory()); - 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()); - } - - try { - writer.save(f); - } catch (IOException e) { - e.printStackTrace(); - ; - } - return; - } - }; - threadd.start(); - } - - public static boolean SignUpdate(String JobName) { - List Copy = new ArrayList(Signs.GetAllSigns().size()); - for (com.gamingmesh.jobs.Signs.Sign foo : Signs.GetAllSigns()) { - Copy.add(foo); - } - int timelapse = 1; - for (com.gamingmesh.jobs.Signs.Sign one : Copy) { - String SignJobName = one.GetJobName(); - if (JobName.equalsIgnoreCase(SignJobName)) { - String SignsWorld = one.GetWorld(); - double SignsX = one.GetX(); - double SignsY = one.GetY(); - double SignsZ = one.GetZ(); - int number = one.GetNumber() - 1; - - List PlayerList = new ArrayList(); - if (!JobName.equalsIgnoreCase("gtoplist")) { - PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number); - } else { - PlayerList = Jobs.getJobsDAO().getGlobalTopList(number); - } - if (PlayerList.size() != 0) { - World world = Bukkit.getWorld(SignsWorld); - if (world == null) - continue; - Location nloc = new Location(world, SignsX, SignsY, SignsZ); - Block block = nloc.getBlock(); - if (!(block.getState() instanceof org.bukkit.block.Sign)) { - Signs.GetAllSigns().remove(one); - saveSigns(); - } else { - org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState(); - if (!one.isSpecial()) { - for (int i = 0; i < 4; i++) { - if (i >= PlayerList.size()) { - break; - } - String PlayerName = ((TopList) PlayerList.get(i)).getPlayerName(); - - if (PlayerName != null && PlayerName.length() > 8) { - String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0]; - PlayerName = PlayerNameStrip + "~"; - } - - if (PlayerName == null) - PlayerName = "Unknown"; - - String line = Language.getMessage("signs.List"); - line = line.replace("[number]", String.valueOf(i + number + 1)); - line = line.replace("[player]", PlayerName); - line = line.replace("[level]", String.valueOf(((TopList) PlayerList.get(i)).getLevel())); - - sign.setLine(i, line); - } - sign.update(); - UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse); - } else { - String PlayerName = ((TopList) PlayerList.get(0)).getPlayerName(); - if (PlayerName.length() > 18) { - String PlayerNameStrip = PlayerName.split("(?<=\\G.{13})")[0]; - PlayerName = PlayerNameStrip + "~"; - } - String line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".1"); - line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); - line1 = line1.replace("[player]", PlayerName); - line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); - - sign.setLine(0, line1); - - line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".2"); - line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); - line1 = line1.replace("[player]", PlayerName); - line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); - - sign.setLine(1, line1); - - line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".3"); - line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); - line1 = line1.replace("[player]", PlayerName); - line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); - - sign.setLine(2, line1); - - line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".4"); - line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); - line1 = line1.replace("[player]", PlayerName); - line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); - - sign.setLine(3, line1); - sign.update(); - UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse); - } - - timelapse++; - } - } - } - } - return true; - } - - public static void UpdateHead(final Location loc, final String Playername, final int timelapse) { - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { - public void run() { - - loc.setY(loc.getY() + 1); - - if (Playername == null) - return; - - Block block = loc.getBlock(); - - if (block == null) - return; - - if (!(block.getState() instanceof Skull)) - return; - - Skull skull = (Skull) block.getState(); - - if (skull == null) - return; - - skull.setOwner(Playername); - skull.update(); - return; - } - }, timelapse * ConfigManager.getJobsConfiguration().InfoUpdateInterval * 20L); - } -} +package com.gamingmesh.jobs.Signs; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.Skull; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.JobsPlugin; +import com.gamingmesh.jobs.config.CommentedYamlConfiguration; +import com.gamingmesh.jobs.config.ConfigManager; +import com.gamingmesh.jobs.container.TopList; +import com.gamingmesh.jobs.i18n.Language; + +public class SignUtil { + + public SignUtil() { + } + + public SignInfo Signs = new SignInfo(); + private JobsPlugin plugin; + + public SignUtil(JobsPlugin plugin) { + this.plugin = plugin; + } + + public SignInfo getSigns(){ + return Signs; + } + + // Sign file + public void LoadSigns() { + Thread threadd = new Thread() { + public void run() { + + Signs.GetAllSigns().clear(); + File file = new File(plugin.getDataFolder(), "Signs.yml"); + YamlConfiguration f = YamlConfiguration.loadConfiguration(file); + + if (!f.isConfigurationSection("Signs")) + return; + + ConfigurationSection ConfCategory = f.getConfigurationSection("Signs"); + ArrayList categoriesList = new ArrayList(ConfCategory.getKeys(false)); + if (categoriesList.size() == 0) + return; + for (String category : categoriesList) { + ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category); + com.gamingmesh.jobs.Signs.Sign newTemp = new com.gamingmesh.jobs.Signs.Sign(); + newTemp.setCategory(Integer.valueOf(category)); + newTemp.setWorld(NameSection.getString("World")); + newTemp.setX(NameSection.getDouble("X")); + newTemp.setY(NameSection.getDouble("Y")); + newTemp.setZ(NameSection.getDouble("Z")); + newTemp.setNumber(NameSection.getInt("Number")); + newTemp.setJobName(NameSection.getString("JobName")); + newTemp.setSpecial(NameSection.getBoolean("Special")); + Signs.addSign(newTemp); + } + return; + } + }; + threadd.start(); + } + + // Signs save file + public void saveSigns() { + + Thread threadd = new Thread() { + public void run() { + File f = new File(plugin.getDataFolder(), "Signs.yml"); + YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); + + CommentedYamlConfiguration writer = new CommentedYamlConfiguration(); + conf.options().copyDefaults(true); + + writer.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!"); + + if (!conf.isConfigurationSection("Signs")) + conf.createSection("Signs"); + + for (com.gamingmesh.jobs.Signs.Sign one : Signs.GetAllSigns()) { + String path = "Signs." + String.valueOf(one.GetCategory()); + 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()); + } + + try { + writer.save(f); + } catch (IOException e) { + e.printStackTrace(); + ; + } + return; + } + }; + threadd.start(); + } + + public boolean SignUpdate(String JobName) { + List Copy = new ArrayList(Signs.GetAllSigns().size()); + for (com.gamingmesh.jobs.Signs.Sign foo : Signs.GetAllSigns()) { + Copy.add(foo); + } + int timelapse = 1; + for (com.gamingmesh.jobs.Signs.Sign one : Copy) { + String SignJobName = one.GetJobName(); + if (JobName.equalsIgnoreCase(SignJobName)) { + String SignsWorld = one.GetWorld(); + double SignsX = one.GetX(); + double SignsY = one.GetY(); + double SignsZ = one.GetZ(); + int number = one.GetNumber() - 1; + + List PlayerList = new ArrayList(); + if (!JobName.equalsIgnoreCase("gtoplist")) { + PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number); + } else { + PlayerList = Jobs.getJobsDAO().getGlobalTopList(number); + } + if (PlayerList.size() != 0) { + World world = Bukkit.getWorld(SignsWorld); + if (world == null) + continue; + Location nloc = new Location(world, SignsX, SignsY, SignsZ); + Block block = nloc.getBlock(); + if (!(block.getState() instanceof org.bukkit.block.Sign)) { + Signs.GetAllSigns().remove(one); + saveSigns(); + } else { + org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState(); + if (!one.isSpecial()) { + for (int i = 0; i < 4; i++) { + if (i >= PlayerList.size()) { + break; + } + String PlayerName = ((TopList) PlayerList.get(i)).getPlayerName(); + + if (PlayerName != null && PlayerName.length() > 8) { + String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0]; + PlayerName = PlayerNameStrip + "~"; + } + + if (PlayerName == null) + PlayerName = "Unknown"; + + String line = Language.getMessage("signs.List"); + line = line.replace("[number]", String.valueOf(i + number + 1)); + line = line.replace("[player]", PlayerName); + line = line.replace("[level]", String.valueOf(((TopList) PlayerList.get(i)).getLevel())); + + sign.setLine(i, line); + } + sign.update(); + UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse); + } else { + String PlayerName = ((TopList) PlayerList.get(0)).getPlayerName(); + if (PlayerName.length() > 18) { + String PlayerNameStrip = PlayerName.split("(?<=\\G.{13})")[0]; + PlayerName = PlayerNameStrip + "~"; + } + String line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".1"); + line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); + line1 = line1.replace("[player]", PlayerName); + line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); + + sign.setLine(0, line1); + + line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".2"); + line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); + line1 = line1.replace("[player]", PlayerName); + line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); + + sign.setLine(1, line1); + + line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".3"); + line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); + line1 = line1.replace("[player]", PlayerName); + line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); + + sign.setLine(2, line1); + + line1 = Language.getMessage("signs.SpecialList." + one.GetNumber() + ".4"); + line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1)); + line1 = line1.replace("[player]", PlayerName); + line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel())); + + sign.setLine(3, line1); + sign.update(); + UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse); + } + + timelapse++; + } + } + } + } + return true; + } + + public void UpdateHead(final Location loc, final String Playername, final int timelapse) { + + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + + loc.setY(loc.getY() + 1); + + if (Playername == null) + return; + + Block block = loc.getBlock(); + + if (block == null) + return; + + if (!(block.getState() instanceof Skull)) + return; + + Skull skull = (Skull) block.getState(); + + if (skull == null) + return; + + skull.setOwner(Playername); + skull.update(); + return; + } + }, timelapse * ConfigManager.getJobsConfiguration().InfoUpdateInterval * 20L); + } +} diff --git a/com/gamingmesh/jobs/commands/JobsCommands.java b/com/gamingmesh/jobs/commands/JobsCommands.java index 1f715cab..3469cfae 100644 --- a/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/com/gamingmesh/jobs/commands/JobsCommands.java @@ -62,13 +62,17 @@ import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.GiveItem; import com.gamingmesh.jobs.stuff.OfflinePlayerList; import com.gamingmesh.jobs.stuff.Perm; -import com.gamingmesh.jobs.stuff.Scboard; import com.gamingmesh.jobs.stuff.Sorting; import com.gamingmesh.jobs.stuff.TimeManage; import com.gamingmesh.jobs.stuff.TranslateName; public class JobsCommands implements CommandExecutor { private static final String label = "jobs"; + private JobsPlugin plugin; + + public JobsCommands(JobsPlugin plugin) { + this.plugin = plugin; + } public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length == 0) @@ -1066,9 +1070,9 @@ public class JobsCommands implements CommandExecutor { return true; } if (!args[0].equalsIgnoreCase("gtoplist")) - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(oldjob.getName()); + Jobs.getSignUtil().SignUpdate(oldjob.getName()); else - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate("gtoplist"); return true; } @@ -1135,7 +1139,7 @@ public class JobsCommands implements CommandExecutor { } player.setScoreboard(board); - Scboard.addNew(player); + Jobs.getScboard().addNew(player); //player.sendMessage(ChatColor.GOLD + Language.getMessage("scoreboard.clear")); @@ -1224,7 +1228,7 @@ public class JobsCommands implements CommandExecutor { player.setScoreboard(board); //player.sendMessage(ChatColor.GOLD + Language.getMessage("scoreboard.clear")); - Scboard.addNew(player); + Jobs.getScboard().addNew(player); int from = start; if (start >= 15) @@ -1485,7 +1489,7 @@ public class JobsCommands implements CommandExecutor { sendUsage(sender, "glog"); return true; } - Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { Map unsortMap = new HashMap(); diff --git a/com/gamingmesh/jobs/config/JobsConfiguration.java b/com/gamingmesh/jobs/config/JobsConfiguration.java index 7db6234f..063258a2 100644 --- a/com/gamingmesh/jobs/config/JobsConfiguration.java +++ b/com/gamingmesh/jobs/config/JobsConfiguration.java @@ -264,8 +264,8 @@ public class JobsConfiguration { loadRestrictedBlocks(); // Item/Block/mobs name list loadItemList(); - // Item/Block/mobs name list - com.gamingmesh.jobs.Signs.SignUtil.LoadSigns(); + // signs information + Jobs.getSignUtil().LoadSigns(); // loadScheduler(); } @@ -1100,7 +1100,7 @@ public class JobsConfiguration { } private synchronized void loadItemList() { - YmlMaker ItemFile = new YmlMaker((JavaPlugin) JobsPlugin.instance, "ItemList.yml"); + YmlMaker ItemFile = new YmlMaker((JavaPlugin) plugin, "ItemList.yml"); ItemFile.saveDefaultConfig(); List section = ItemFile.getConfig().getStringList("ItemList"); ListOfNames.clear(); @@ -1208,7 +1208,7 @@ public class JobsConfiguration { languages.add("ru"); for (String lang : languages) { - YmlMaker langFile = new YmlMaker((JavaPlugin) JobsPlugin.instance, "locale" + File.separator + "messages_" + lang + ".yml"); + YmlMaker langFile = new YmlMaker((JavaPlugin) plugin, "locale" + File.separator + "messages_" + lang + ".yml"); if (langFile != null) langFile.saveDefaultConfig(); } diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index bf8e0749..b0e8fe1a 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -60,6 +60,11 @@ public abstract class JobsDAO { private JobsConnectionPool pool; private String prefix; + private JobsPlugin plugin; + + public JobsDAO(JobsPlugin plugin) { + this.plugin = plugin; + } protected JobsDAO(String driverName, String url, String username, String password, String prefix) { this.prefix = prefix; @@ -492,7 +497,7 @@ public abstract class JobsDAO { } public void fixUuid(final CommandSender sender) { - Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { JobsConnection conn = getConnection(); @@ -539,7 +544,7 @@ public abstract class JobsDAO { } public void fixName(final CommandSender sender) { - Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { JobsConnection conn = getConnection(); diff --git a/com/gamingmesh/jobs/i18n/Language.java b/com/gamingmesh/jobs/i18n/Language.java index b185997a..60f43b02 100644 --- a/com/gamingmesh/jobs/i18n/Language.java +++ b/com/gamingmesh/jobs/i18n/Language.java @@ -28,57 +28,62 @@ import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.YmlMaker; public class Language { - public static FileConfiguration enlocale; - public static FileConfiguration customlocale; + public static FileConfiguration enlocale; + public static FileConfiguration customlocale; + private JobsPlugin plugin; - static { - customlocale = new YmlMaker((JavaPlugin) JobsPlugin.instance, "locale/messages_" + ConfigManager.getJobsConfiguration().localeString + ".yml").getConfig(); - enlocale = new YmlMaker((JavaPlugin) JobsPlugin.instance, "locale/messages_en.yml").getConfig(); - if (customlocale == null) - customlocale = enlocale; - } + public Language(JobsPlugin plugin) { + this.plugin = plugin; + } - private Language() { - } +// static { +// customlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_" + ConfigManager.getJobsConfiguration().localeString + ".yml").getConfig(); +// enlocale = new YmlMaker((JavaPlugin) JobsPlugin.instance, "locale/messages_en.yml").getConfig(); +// if (customlocale == null) +// customlocale = enlocale; +// } - /** - * Reloads the config - */ - public static void reload(Locale locale) { - customlocale = new YmlMaker((JavaPlugin) JobsPlugin.instance, "locale/messages_" + ConfigManager.getJobsConfiguration().localeString + ".yml").getConfig(); - enlocale = new YmlMaker((JavaPlugin) JobsPlugin.instance, "locale/messages_en.yml").getConfig(); - if (customlocale == null) - customlocale = enlocale; - } + public Language() { + } - /** - * Get the message with the correct key - * @param key - the key of the message - * @return the message - */ + /** + * Reloads the config + */ + public void reload(Locale locale) { + customlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_" + ConfigManager.getJobsConfiguration().localeString + ".yml").getConfig(); + enlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_en.yml").getConfig(); + if (customlocale == null) + customlocale = enlocale; + } + + /** + * Get the message with the correct key + * @param key - the key of the message + * @return the message + */ public static String getMessage(String key) { - if (customlocale == null || !customlocale.contains(key)) - return enlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', enlocale.getString(key)) : "Cant find locale"; - return customlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', customlocale.getString(key)) : "Cant find locale"; - } + if (customlocale == null || !customlocale.contains(key)) + return enlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', enlocale.getString(key)) : "Cant find locale"; + return customlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', customlocale.getString(key)) : "Cant find locale"; + } - /** - * Get the message with the correct key - * @param key - the key of the message - * @return the message - */ - public static String getDefaultMessage(String key) { - return enlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', enlocale.getString(key)) : "Cant find locale"; - } - - /** - * Check if key exists - * @param key - the key of the message - * @return true/false - */ - public static boolean containsKey(String key) { - if (customlocale == null || !customlocale.contains(key)) - return enlocale.contains(key); - return customlocale.contains(key); - } + /** + * Get the message with the correct key + * @param key - the key of the message + * @return the message + */ + public static String getDefaultMessage(String key) { + return enlocale.contains(key) == true ? ChatColor.translateAlternateColorCodes('&', enlocale.getString(key)) : "Cant find locale"; + } + + /** + * Check if key exists + * @param key - the key of the message + * @return true/false + */ + public static boolean containsKey(String key) { + if (customlocale == null || !customlocale.contains(key)) + return enlocale.contains(key); + return customlocale.contains(key); + } } diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index 35f2f266..396398f7 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -53,7 +53,6 @@ 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; import com.gamingmesh.jobs.container.JobsPlayer; @@ -229,7 +228,7 @@ public class JobsListener implements Listener { Location loc = block.getLocation(); - for (com.gamingmesh.jobs.Signs.Sign one : SignUtil.Signs.GetAllSigns()) { + for (com.gamingmesh.jobs.Signs.Sign one : Jobs.getSignUtil().getSigns().GetAllSigns()) { if (one.GetX() != loc.getBlockX()) continue; @@ -244,8 +243,8 @@ public class JobsListener implements Listener { return; } - SignUtil.Signs.removeSign(one); - SignUtil.saveSigns(); + Jobs.getSignUtil().getSigns().removeSign(one); + Jobs.getSignUtil().saveSigns(); break; } } @@ -310,8 +309,8 @@ public class JobsListener implements Listener { Location loc = sign.getLocation(); int category = 1; - if (com.gamingmesh.jobs.Signs.SignUtil.Signs.GetAllSigns().size() > 0) - category = com.gamingmesh.jobs.Signs.SignUtil.Signs.GetAllSigns().get(com.gamingmesh.jobs.Signs.SignUtil.Signs.GetAllSigns().size() - 1).GetCategory() + 1; + if (Jobs.getSignUtil().getSigns().GetAllSigns().size() > 0) + category = Jobs.getSignUtil().getSigns().GetAllSigns().get(Jobs.getSignUtil().getSigns().GetAllSigns().size() - 1).GetCategory() + 1; signInfo.setNumber(Number); signInfo.setWorld(loc.getWorld().getName()); signInfo.setX(loc.getX()); @@ -324,16 +323,16 @@ public class JobsListener implements Listener { signInfo.setJobName("gtoplist"); signInfo.setSpecial(special); - com.gamingmesh.jobs.Signs.SignUtil.Signs.addSign(signInfo); - com.gamingmesh.jobs.Signs.SignUtil.saveSigns(); + Jobs.getSignUtil().getSigns().addSign(signInfo); + Jobs.getSignUtil().saveSigns(); event.setCancelled(true); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { if (!signtype.equalsIgnoreCase("gtoplist")) - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate(job.getName()); + Jobs.getSignUtil().SignUpdate(job.getName()); else - com.gamingmesh.jobs.Signs.SignUtil.SignUpdate("gtoplist"); + Jobs.getSignUtil().SignUpdate("gtoplist"); return; } }, 1L); @@ -466,7 +465,7 @@ public class JobsListener implements Listener { if (!ConfigManager.getJobsConfiguration().WaterBlockBreake) return; if (event.getBlock().getState().hasMetadata(JobsPaymentListener.PlacedBlockMetadata)) { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { event.getBlock().getState().removeMetadata(JobsPaymentListener.PlacedBlockMetadata, plugin); return; diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 49624f35..b2272be0 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -931,6 +931,12 @@ public class JobsPaymentListener implements Listener { // Calulating multiplaier multiplier = multiplier * NearSpawnerMultiplier * PetPayMultiplier; + if (lVictim instanceof Player && !lVictim.hasMetadata("NPC")) { + Player VPlayer = (Player) lVictim; + if (jDamager.getUserName().equalsIgnoreCase(VPlayer.getName())) + return; + } + Jobs.action(jDamager, new EntityActionInfo(lVictim, ActionType.KILL), multiplier, item, armor); // Payment for killing player with particular job, except NPC's diff --git a/com/gamingmesh/jobs/stuff/ActionBar.java b/com/gamingmesh/jobs/stuff/ActionBar.java index b750d96a..ccab9faa 100644 --- a/com/gamingmesh/jobs/stuff/ActionBar.java +++ b/com/gamingmesh/jobs/stuff/ActionBar.java @@ -1,154 +1,157 @@ -package com.gamingmesh.jobs.stuff; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Level; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.economy.BufferedPayment; -import com.gamingmesh.jobs.i18n.Language; - -/** -* -* @author hamzaxx -*/ -public class ActionBar { - private static int cleanVersion = 182; - private static String version = ""; - private static Object packet; - private static Method getHandle; - private static Method sendPacket; - private static Field playerConnection; - private static Class nmsChatSerializer; - private static Class nmsIChatBaseComponent; - private static Class packetType; - - static { - try { - version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - - // Translating version to integer for simpler use - try { - cleanVersion = Integer.parseInt(version.replace("v", "").replace("V", "").replace("_", "").replace("r", "").replace("R", "")); - } catch (NumberFormatException e) { - // Fail save if it for some reason can't translate version to integer - if (version.contains("v1_7")) - cleanVersion = 170; - if (version.contains("v1_6")) - cleanVersion = 160; - if (version.contains("v1_5")) - cleanVersion = 150; - if (version.contains("v1_4")) - cleanVersion = 140; - if (version.contains("v1_8_R1")) - cleanVersion = 181; - if (version.contains("v1_8_R2")) - cleanVersion = 182; - if (version.contains("v1_8_R3")) - cleanVersion = 183; - } - - packetType = Class.forName(getPacketPlayOutChat()); - Class typeCraftPlayer = Class.forName(getCraftPlayerClasspath()); - Class typeNMSPlayer = Class.forName(getNMSPlayerClasspath()); - Class typePlayerConnection = Class.forName(getPlayerConnectionClasspath()); - nmsChatSerializer = Class.forName(getChatSerializerClasspath()); - nmsIChatBaseComponent = Class.forName(getIChatBaseComponentClasspath()); - getHandle = typeCraftPlayer.getMethod("getHandle"); - playerConnection = typeNMSPlayer.getField("playerConnection"); - sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath())); - - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | NoSuchFieldException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex); - } - } - - public static void ShowActionBar(BufferedPayment payment) { - String playername = payment.getOfflinePlayer().getName(); - if (!Jobs.actionbartoggle.containsKey(playername) && ConfigManager.getJobsConfiguration().JobsToggleEnabled) - Jobs.actionbartoggle.put(playername, true); - - if (playername != null && Jobs.actionbartoggle.size() > 0) - if (Jobs.actionbartoggle.containsKey(playername)) { - Boolean show = Jobs.actionbartoggle.get(playername); - Player abp = (Player) payment.getOfflinePlayer(); - if (abp != null && show) { - String Message = Language.getMessage("command.toggle.output.paid"); - Message = Message.replace("[amount]", String.valueOf((((int) (payment.getAmount() * 100)) / 100.0))); - Message = Message.replace("[exp]", String.valueOf((((int) (payment.getExp() * 100)) / 100.0))); - ActionBar.send(abp, ChatColor.GREEN + Message); - } - } - } - - public static void send(Player receivingPacket, String msg) { - try { - if (msg == null || nmsChatSerializer == null) - return; - - if (cleanVersion < 180) { - receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); - return; - } - - Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', msg) + "\"}"); - if (cleanVersion > 180) { - packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) 2); - } else { - packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2); - } - Object player = getHandle.invoke(receivingPacket); - Object connection = playerConnection.get(player); - sendPacket.invoke(connection, packet); - } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex); - } - - try { - Object player = getHandle.invoke(receivingPacket); - Object connection = playerConnection.get(player); - sendPacket.invoke(connection, packet); - } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex); - } - } - - private static String getCraftPlayerClasspath() { - return "org.bukkit.craftbukkit." + version + ".entity.CraftPlayer"; - } - - private static String getPlayerConnectionClasspath() { - return "net.minecraft.server." + version + ".PlayerConnection"; - } - - private static String getNMSPlayerClasspath() { - return "net.minecraft.server." + version + ".EntityPlayer"; - } - - private static String getPacketClasspath() { - return "net.minecraft.server." + version + ".Packet"; - } - - private static String getIChatBaseComponentClasspath() { - return "net.minecraft.server." + version + ".IChatBaseComponent"; - } - - private static String getChatSerializerClasspath() { - - if (cleanVersion < 182) { - return "net.minecraft.server." + version + ".ChatSerializer"; - } else { - return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent - } - } - - private static String getPacketPlayOutChat() { - return "net.minecraft.server." + version + ".PacketPlayOutChat"; - } +package com.gamingmesh.jobs.stuff; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Level; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.config.ConfigManager; +import com.gamingmesh.jobs.economy.BufferedPayment; +import com.gamingmesh.jobs.i18n.Language; + +/** +* +* @author hamzaxx +*/ +public class ActionBar { + private static int cleanVersion = 1820; + private static String version = ""; + private static Object packet; + private static Method getHandle; + private static Method sendPacket; + private static Field playerConnection; + private static Class nmsChatSerializer; + private static Class nmsIChatBaseComponent; + private static Class packetType; + + static { + try { + version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + + // Translating version to integer for simpler use + try { + cleanVersion = Integer.parseInt(version.replace("v", "").replace("V", "").replace("_", "").replace("r", "").replace("R", "")); + } catch (NumberFormatException e) { + // Fail save if it for some reason can't translate version to integer + if (version.contains("v1_7")) + cleanVersion = 1700; + if (version.contains("v1_6")) + cleanVersion = 1600; + if (version.contains("v1_5")) + cleanVersion = 1500; + if (version.contains("v1_4")) + cleanVersion = 1400; + if (version.contains("v1_8_R1")) + cleanVersion = 1810; + if (version.contains("v1_8_R2")) + cleanVersion = 1820; + if (version.contains("v1_8_R3")) + cleanVersion = 1830; + } + + if (cleanVersion < 1000) + cleanVersion = cleanVersion * 10; + + packetType = Class.forName(getPacketPlayOutChat()); + Class typeCraftPlayer = Class.forName(getCraftPlayerClasspath()); + Class typeNMSPlayer = Class.forName(getNMSPlayerClasspath()); + Class typePlayerConnection = Class.forName(getPlayerConnectionClasspath()); + nmsChatSerializer = Class.forName(getChatSerializerClasspath()); + nmsIChatBaseComponent = Class.forName(getIChatBaseComponentClasspath()); + getHandle = typeCraftPlayer.getMethod("getHandle"); + playerConnection = typeNMSPlayer.getField("playerConnection"); + sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(getPacketClasspath())); + + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | NoSuchFieldException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex); + } + } + + public static void ShowActionBar(BufferedPayment payment) { + String playername = payment.getOfflinePlayer().getName(); + if (!Jobs.actionbartoggle.containsKey(playername) && ConfigManager.getJobsConfiguration().JobsToggleEnabled) + Jobs.actionbartoggle.put(playername, true); + + if (playername != null && Jobs.actionbartoggle.size() > 0) + if (Jobs.actionbartoggle.containsKey(playername)) { + Boolean show = Jobs.actionbartoggle.get(playername); + Player abp = (Player) payment.getOfflinePlayer(); + if (abp != null && show) { + String Message = Language.getMessage("command.toggle.output.paid"); + Message = Message.replace("[amount]", String.format("%.2f", payment.getAmount())); + Message = Message.replace("[exp]", String.format("%.2f", payment.getExp())); + ActionBar.send(abp, ChatColor.GREEN + Message); + } + } + } + + public static void send(Player receivingPacket, String msg) { + try { + if (msg == null || nmsChatSerializer == null) + return; + + if (cleanVersion < 1800) { + receivingPacket.sendMessage(ChatColor.translateAlternateColorCodes('&', msg)); + return; + } + + Object serialized = nmsChatSerializer.getMethod("a", String.class).invoke(null, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', msg) + "\"}"); + if (cleanVersion > 1800) { + packet = packetType.getConstructor(nmsIChatBaseComponent, byte.class).newInstance(serialized, (byte) 2); + } else { + packet = packetType.getConstructor(nmsIChatBaseComponent, int.class).newInstance(serialized, 2); + } + Object player = getHandle.invoke(receivingPacket); + Object connection = playerConnection.get(player); + sendPacket.invoke(connection, packet); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex); + } + + try { + Object player = getHandle.invoke(receivingPacket); + Object connection = playerConnection.get(player); + sendPacket.invoke(connection, packet); + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Error {0}", ex); + } + } + + private static String getCraftPlayerClasspath() { + return "org.bukkit.craftbukkit." + version + ".entity.CraftPlayer"; + } + + private static String getPlayerConnectionClasspath() { + return "net.minecraft.server." + version + ".PlayerConnection"; + } + + private static String getNMSPlayerClasspath() { + return "net.minecraft.server." + version + ".EntityPlayer"; + } + + private static String getPacketClasspath() { + return "net.minecraft.server." + version + ".Packet"; + } + + private static String getIChatBaseComponentClasspath() { + return "net.minecraft.server." + version + ".IChatBaseComponent"; + } + + private static String getChatSerializerClasspath() { + + if (cleanVersion < 1820) { + return "net.minecraft.server." + version + ".ChatSerializer"; + } else { + return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent + } + } + + private static String getPacketPlayOutChat() { + return "net.minecraft.server." + version + ".PacketPlayOutChat"; + } } \ No newline at end of file diff --git a/com/gamingmesh/jobs/stuff/Debug.java b/com/gamingmesh/jobs/stuff/Debug.java index b6fbbc0f..7766bd47 100644 --- a/com/gamingmesh/jobs/stuff/Debug.java +++ b/com/gamingmesh/jobs/stuff/Debug.java @@ -1,18 +1,15 @@ -package com.gamingmesh.jobs.stuff; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -public class Debug { - public static void D(String message) { - - Player player = Bukkit.getPlayer("Zrips"); - if (player == null) - return; - - player.sendMessage(ChatColor.DARK_GRAY + "[Debug] " + ChatColor.DARK_AQUA + ChatColor.translateAlternateColorCodes('&', message)); - - return; - } -} +package com.gamingmesh.jobs.stuff; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +public class Debug { + public static void D(String message) { + Player player = Bukkit.getPlayer("Zrips"); + if (player == null) + return; + player.sendMessage(ChatColor.DARK_GRAY + "[Debug] " + ChatColor.DARK_AQUA + ChatColor.translateAlternateColorCodes('&', message)); + return; + } +} diff --git a/com/gamingmesh/jobs/stuff/Loging.java b/com/gamingmesh/jobs/stuff/Loging.java index 244a4420..91d5b7cf 100644 --- a/com/gamingmesh/jobs/stuff/Loging.java +++ b/com/gamingmesh/jobs/stuff/Loging.java @@ -1,56 +1,56 @@ -package com.gamingmesh.jobs.stuff; - -import java.util.List; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.container.ActionInfo; -import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.container.Log; - -public class Loging { - - public static void recordToLog(JobsPlayer jPlayer, ActionInfo info, double amount, double expAmount) { - recordToLog(jPlayer, info.getType().getName(), info.getNameWithSub(), amount, expAmount); - } - - public static void recordToLog(JobsPlayer jPlayer, String ActionName, String item, double amount, double expAmount) { - List logList = jPlayer.getLog(); - boolean found = false; - - if (jPlayer.getLog().size() > 0 && ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) { - ScheduleUtil.dateByInt = TimeManage.timeInInt(); - if (ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) { - Jobs.getJobsDAO().saveLog(jPlayer); - jPlayer.getLog().clear(); - } - } - - for (Log one : logList) { - if (!one.getActionType().equalsIgnoreCase(ActionName)) - continue; - one.add(item, amount, expAmount); - found = true; - } - if (!found) { - Log log = new Log(ActionName); - log.add(item, amount, expAmount); - logList.add(log); - } - } - - public static void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, double money, double expAmount) { - List logList = jPlayer.getLog(); - boolean found = false; - for (Log one : logList) { - if (!one.getActionType().equalsIgnoreCase(ActionName)) - continue; - one.add(item, count, money, expAmount); - found = true; - } - if (!found) { - Log log = new Log(ActionName); - log.add(item, count, money, expAmount); - logList.add(log); - } - } -} +package com.gamingmesh.jobs.stuff; + +import java.util.List; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.ActionInfo; +import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.Log; + +public class Loging { + + public static void recordToLog(JobsPlayer jPlayer, ActionInfo info, double amount, double expAmount) { + recordToLog(jPlayer, info.getType().getName(), info.getNameWithSub(), amount, expAmount); + } + + public static void recordToLog(JobsPlayer jPlayer, String ActionName, String item, double amount, double expAmount) { + List logList = jPlayer.getLog(); + boolean found = false; + + if (jPlayer.getLog().size() > 0 && Jobs.getSchedule().getDateByInt() != jPlayer.getLog().get(0).getDate()) { + Jobs.getSchedule().setDateByInt(TimeManage.timeInInt()); + if (Jobs.getSchedule().getDateByInt() != jPlayer.getLog().get(0).getDate()) { + Jobs.getJobsDAO().saveLog(jPlayer); + jPlayer.getLog().clear(); + } + } + + for (Log one : logList) { + if (!one.getActionType().equalsIgnoreCase(ActionName)) + continue; + one.add(item, amount, expAmount); + found = true; + } + if (!found) { + Log log = new Log(ActionName); + log.add(item, amount, expAmount); + logList.add(log); + } + } + + public static void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, double money, double expAmount) { + List logList = jPlayer.getLog(); + boolean found = false; + for (Log one : logList) { + if (!one.getActionType().equalsIgnoreCase(ActionName)) + continue; + one.add(item, count, money, expAmount); + found = true; + } + if (!found) { + Log log = new Log(ActionName); + log.add(item, count, money, expAmount); + logList.add(log); + } + } +} diff --git a/com/gamingmesh/jobs/stuff/Scboard.java b/com/gamingmesh/jobs/stuff/Scboard.java index 08383133..4d62738b 100644 --- a/com/gamingmesh/jobs/stuff/Scboard.java +++ b/com/gamingmesh/jobs/stuff/Scboard.java @@ -13,10 +13,17 @@ import com.gamingmesh.jobs.config.ConfigManager; public class Scboard { - private static ConcurrentHashMap timerMap = new ConcurrentHashMap(); + private ConcurrentHashMap timerMap = new ConcurrentHashMap(); + private JobsPlugin plugin; - private static void RunScheduler() { + public Scboard() { + } + public Scboard(JobsPlugin plugin) { + this.plugin = plugin; + } + + private void RunScheduler() { Iterator> MeinMapIter = timerMap.entrySet().iterator(); while (MeinMapIter.hasNext()) { Entry Map = MeinMapIter.next(); @@ -31,7 +38,7 @@ public class Scboard { } if (timerMap.size() > 0) - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { RunScheduler(); return; @@ -40,7 +47,7 @@ public class Scboard { return; } - public static void addNew(Player player) { + public void addNew(Player player) { timerMap.put(player.getName(), System.currentTimeMillis()); RunScheduler(); } diff --git a/com/gamingmesh/jobs/stuff/ScheduleUtil.java b/com/gamingmesh/jobs/stuff/ScheduleUtil.java index 38b5dad8..b3d4020d 100644 --- a/com/gamingmesh/jobs/stuff/ScheduleUtil.java +++ b/com/gamingmesh/jobs/stuff/ScheduleUtil.java @@ -1,133 +1,149 @@ -package com.gamingmesh.jobs.stuff; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import org.bukkit.Bukkit; - -import com.gamingmesh.jobs.JobsPlugin; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.container.Schedule; -import com.gamingmesh.jobs.i18n.Language; - -public class ScheduleUtil { - - public static int dateByInt = 0; - - public static void DateUpdater() { - if (dateByInt == 0) - dateByInt = TimeManage.timeInInt(); - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { - public void run() { - - dateByInt = TimeManage.timeInInt(); - - DateUpdater(); - return; - } - }, 60 * 20L); - } - - public static boolean scheduler() { - if (ConfigManager.getJobsConfiguration().BoostSchedule.size() > 0 && ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) { - - DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); - Date date = new Date(); - - String currenttime = dateFormat.format(date); - - int Current = Integer.valueOf(currenttime.replace(":", "")).intValue(); - - String CurrentDayName = GetWeekDay(); - - for (Schedule one : ConfigManager.getJobsConfiguration().BoostSchedule) { - - int From = one.GetFrom(); - int Until = one.GetUntil(); - - List days = one.GetDays(); - - if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.GetBroadcastInterval() > 0) { - one.setBroadcastInfoOn(System.currentTimeMillis() + one.GetBroadcastInterval() * 60 * 1000); - for (String oneMsg : one.GetMessageToBroadcast()) { - Bukkit.broadcastMessage(oneMsg); - } - } - - if (((one.isNextDay() && (Current >= From && Current < one.GetUntil() || Current >= one.GetNextFrom() && Current < one.GetNextUntil()) && !one - .isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one - .isStarted()) { - - if (one.isBroadcastOnStart()) - if (one.GetMessageOnStart().size() == 0) - Bukkit.broadcastMessage(Language.getMessage("message.boostStarted")); - else - for (String oneMsg : one.GetMessageOnStart()) { - Bukkit.broadcastMessage(oneMsg); - } - - for (Job onejob : one.GetJobs()) { - onejob.setExpBoost(one.GetExpBoost()); - onejob.setMoneyBoost(one.GetMoneyBoost()); - } - - one.setBroadcastInfoOn(System.currentTimeMillis() + one.GetBroadcastInterval() * 60 * 1000); - - one.setStarted(true); - one.setStoped(false); - break; - } else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until - && ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) { - if (one.isBroadcastOnStop()) - if (one.GetMessageOnStop().size() == 0) - Bukkit.broadcastMessage(Language.getMessage("message.boostStoped")); - else - for (String oneMsg : one.GetMessageOnStop()) { - Bukkit.broadcastMessage(oneMsg); - } - for (Job onejob : one.GetJobs()) { - onejob.setExpBoost(1.0); - onejob.setMoneyBoost(1.0); - } - one.setStoped(true); - one.setStarted(false); - } - - } - - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() { - public void run() { - scheduler(); - return; - } - }, 30 * 20L); - } - return true; - } - - public static String GetWeekDay() { - Calendar c = Calendar.getInstance(); - int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); - switch (dayOfWeek) { - case 2: - return "monday"; - case 3: - return "tuesday"; - case 4: - return "wednesday"; - case 5: - return "thursday"; - case 6: - return "friday"; - case 7: - return "saturday"; - case 1: - return "sunday"; - } - return "all"; - } -} +package com.gamingmesh.jobs.stuff; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import org.bukkit.Bukkit; + +import com.gamingmesh.jobs.JobsPlugin; +import com.gamingmesh.jobs.config.ConfigManager; +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.container.Schedule; +import com.gamingmesh.jobs.i18n.Language; + +public class ScheduleUtil { + + public int dateByInt = 0; + + private JobsPlugin plugin; + + public ScheduleUtil() { + } + + public ScheduleUtil(JobsPlugin plugin) { + this.plugin = plugin; + } + + public int getDateByInt(){ + return dateByInt; + } + public void setDateByInt(int time){ + dateByInt = time; + } + + public void DateUpdater() { + if (dateByInt == 0) + dateByInt = TimeManage.timeInInt(); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + + dateByInt = TimeManage.timeInInt(); + + DateUpdater(); + return; + } + }, 60 * 20L); + } + + public boolean scheduler() { + if (ConfigManager.getJobsConfiguration().BoostSchedule.size() > 0 && ConfigManager.getJobsConfiguration().useGlobalBoostScheduler) { + + DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); + Date date = new Date(); + + String currenttime = dateFormat.format(date); + + int Current = Integer.valueOf(currenttime.replace(":", "")).intValue(); + + String CurrentDayName = GetWeekDay(); + + for (Schedule one : ConfigManager.getJobsConfiguration().BoostSchedule) { + + int From = one.GetFrom(); + int Until = one.GetUntil(); + + List days = one.GetDays(); + + if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.GetBroadcastInterval() > 0) { + one.setBroadcastInfoOn(System.currentTimeMillis() + one.GetBroadcastInterval() * 60 * 1000); + for (String oneMsg : one.GetMessageToBroadcast()) { + Bukkit.broadcastMessage(oneMsg); + } + } + + if (((one.isNextDay() && (Current >= From && Current < one.GetUntil() || Current >= one.GetNextFrom() && Current < one.GetNextUntil()) && !one + .isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one + .isStarted()) { + + if (one.isBroadcastOnStart()) + if (one.GetMessageOnStart().size() == 0) + Bukkit.broadcastMessage(Language.getMessage("message.boostStarted")); + else + for (String oneMsg : one.GetMessageOnStart()) { + Bukkit.broadcastMessage(oneMsg); + } + + for (Job onejob : one.GetJobs()) { + onejob.setExpBoost(one.GetExpBoost()); + onejob.setMoneyBoost(one.GetMoneyBoost()); + } + + one.setBroadcastInfoOn(System.currentTimeMillis() + one.GetBroadcastInterval() * 60 * 1000); + + one.setStarted(true); + one.setStoped(false); + break; + } else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until + && ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) { + if (one.isBroadcastOnStop()) + if (one.GetMessageOnStop().size() == 0) + Bukkit.broadcastMessage(Language.getMessage("message.boostStoped")); + else + for (String oneMsg : one.GetMessageOnStop()) { + Bukkit.broadcastMessage(oneMsg); + } + for (Job onejob : one.GetJobs()) { + onejob.setExpBoost(1.0); + onejob.setMoneyBoost(1.0); + } + one.setStoped(true); + one.setStarted(false); + } + + } + + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + scheduler(); + return; + } + }, 30 * 20L); + } + return true; + } + + public static String GetWeekDay() { + Calendar c = Calendar.getInstance(); + int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); + switch (dayOfWeek) { + case 2: + return "monday"; + case 3: + return "tuesday"; + case 4: + return "wednesday"; + case 5: + return "thursday"; + case 6: + return "friday"; + case 7: + return "saturday"; + case 1: + return "sunday"; + } + return "all"; + } +} diff --git a/plugin.yml b/plugin.yml index ccbf23f6..c1a85105 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: 2.55.1 +version: 2.56.0 author: phrstbrn softdepend: [Vault, CoreProtect, MythicMobs, McMMO] commands: