From 43abccf7d75cbc8e8b9afad52f66ef9536f0e1bb Mon Sep 17 00:00:00 2001 From: Zrips Date: Fri, 27 Nov 2015 16:34:19 +0200 Subject: [PATCH] GUI and 1.7 support --- com/gamingmesh/jobs/.gitignore | 1 + com/gamingmesh/jobs/Gui/GuiTools.java | 493 +++++++++--------- com/gamingmesh/jobs/JobsPlugin.java | 43 ++ com/gamingmesh/jobs/NMS.java | 13 + .../jobs/actions/EntityActionInfo.java | 10 +- .../jobs/commands/JobsCommands.java | 18 +- .../jobs/config/JobsConfiguration.java | 15 +- .../jobs/listeners/JobsListener.java | 87 +--- .../jobs/listeners/JobsPaymentListener.java | 4 +- .../listeners/PistonProtectionListener.java | 242 ++++----- com/gamingmesh/jobs/nmsUtil/.gitignore | 2 + com/gamingmesh/jobs/nmsUtil/v1_7.java | 23 + com/gamingmesh/jobs/nmsUtil/v1_8.java | 30 ++ jobConfig.yml | 6 + plugin.yml | 2 +- 15 files changed, 543 insertions(+), 446 deletions(-) create mode 100644 com/gamingmesh/jobs/NMS.java create mode 100644 com/gamingmesh/jobs/nmsUtil/.gitignore create mode 100644 com/gamingmesh/jobs/nmsUtil/v1_7.java create mode 100644 com/gamingmesh/jobs/nmsUtil/v1_8.java diff --git a/com/gamingmesh/jobs/.gitignore b/com/gamingmesh/jobs/.gitignore index f5ef64fe..8f6937d8 100644 --- a/com/gamingmesh/jobs/.gitignore +++ b/com/gamingmesh/jobs/.gitignore @@ -5,3 +5,4 @@ /PlayerManager.class /Jobs$1.class /PlayerManager$1.class +/NMS.class diff --git a/com/gamingmesh/jobs/Gui/GuiTools.java b/com/gamingmesh/jobs/Gui/GuiTools.java index 8a041d41..6dd04e84 100644 --- a/com/gamingmesh/jobs/Gui/GuiTools.java +++ b/com/gamingmesh/jobs/Gui/GuiTools.java @@ -1,241 +1,252 @@ -package com.gamingmesh.jobs.Gui; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.commands.JobsCommands; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.container.ActionType; -import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.container.JobInfo; -import com.gamingmesh.jobs.container.JobProgression; -import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.TranslateName; - -public class GuiTools { - - public static HashMap GuiList = new HashMap(); - - public static Inventory CreateJobsGUI(Player player) { - - ArrayList JobsList = new ArrayList(); - for (Job job : Jobs.getJobs()) { - if (ConfigManager.getJobsConfiguration().getHideJobsWithoutPermission()) - if (!JobsCommands.hasJobPermission(player, job)) - continue; - JobsList.add(job); - } - - GuiInfoList guiInfo = new GuiInfoList(player.getName()); - guiInfo.setJobList(JobsList); - GuiList.put(player.getName(), guiInfo); - - int GuiSize = 9; - - if (JobsList.size() > 9) - GuiSize = 18; - - if (JobsList.size() > 18) - GuiSize = 27; - - if (JobsList.size() > 27) - GuiSize = 36; - - if (JobsList.size() > 36) - GuiSize = 45; - - if (JobsList.size() > 45) - GuiSize = 54; - - JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - - List pJobs = JPlayer.getJobProgression(); - - Inventory GuiInv = Bukkit.createInventory(null, GuiSize, "Pick your job!"); - - for (int i = 0; i < JobsList.size(); i++) { - - Job job = JobsList.get(i); - - ArrayList Lore = new ArrayList(); - - for (JobProgression onePJob : pJobs) { - if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) - Lore.add(ChatColor.translateAlternateColorCodes('&', "&2Working ")); - } - - int maxlevel = 0; - if (player.hasPermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0) - maxlevel = job.getVipMaxLevel(); - else - maxlevel = job.getMaxLevel(); - - if (maxlevel > 0) - Lore.add("Max level: " + maxlevel); - - Lore.add(job.getDescription()); - - if (job.getMaxSlots() != null) - Lore.add("Left slots: " + (job.getMaxSlots() - Jobs.getUsedSlots(job))); - - Lore.add(""); - Lore.add("Posible actions"); - for (ActionType actionType : ActionType.values()) { - List info = job.getJobInfo(actionType); - - if (info != null && !info.isEmpty()) { - Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); - } - } - - ItemStack GuiItem = job.getGuiItem(); - - ItemMeta meta = GuiItem.getItemMeta(); - meta.setDisplayName(job.getName()); - meta.setLore(Lore); - GuiItem.setItemMeta(meta); - - GuiInv.setItem(i, GuiItem); - } - return GuiInv; - } - - public static Inventory CreateJobsSubGUI(Player player, Job job) { - - Inventory tempInv = Bukkit.createInventory(null, 54, ""); - - ItemStack GuiItem = job.getGuiItem(); - JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - - // money exp boost - Player dude = Bukkit.getServer().getPlayer(player.getUniqueId()); - Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job); - Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job); - - - int level = 1; - JobProgression prog = JPlayer.getJobProgression(job); - if (prog != null) - level = prog.getLevel(); - - int numjobs = JPlayer.getJobProgression().size(); - - List items = new ArrayList(); - int i = 0; - for (ActionType actionType : ActionType.values()) { - List info = job.getJobInfo(actionType); - - if (info == null || info.isEmpty()) - continue; - - ArrayList Lore = new ArrayList(); - Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); - int y = 1; - for (int z = 0; z < info.size(); z++) { - String itemName = TranslateName.Translate(info.get(z).getName(), info.get(z)); - - double income = info.get(z).getIncome(level, numjobs); - income = income + ((income * MoneyBoost) - income) + ((income * job.getMoneyBoost()) - income); - ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED; - - double xp = info.get(z).getExperience(level, numjobs); - xp = xp + ((xp * ExpBoost) - xp) + ((xp * job.getExpBoost()) - xp); - ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY; - - String xpString = String.format("%.2fxp", xp); - - Lore.add(ChatColor.translateAlternateColorCodes('&', "&7" + itemName + " " + xpColor + xpString + " " + incomeColor + Jobs.getEconomy().format(income))); - - if (y >= 10) { - y = 1; - - if (z == info.size() - 1) - continue; - ItemMeta meta = GuiItem.getItemMeta(); - meta.setDisplayName(job.getName()); - meta.setLore(Lore); - GuiItem.setItemMeta(meta); - //GuiInv.setItem(i, GuiItem); - tempInv.setItem(i, GuiItem); - - GuiItem = job.getGuiItem(); - Lore = new ArrayList(); - Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); - i++; - } - y++; - } - ItemMeta meta = GuiItem.getItemMeta(); - meta.setDisplayName(job.getName()); - meta.setLore(Lore); - GuiItem.setItemMeta(meta); - //GuiInv.setItem(i, GuiItem); - tempInv.setItem(i, GuiItem); - i++; - } - - for (ItemStack one : tempInv.getContents()) { - if (one != null) - items.add(one); - } - - int GuiSize = 27; - int backButton = 18; - - if (items.size() > 9) { - GuiSize = 36; - backButton = 27; - } - - if (items.size() > 18) { - GuiSize = 45; - backButton = 36; - } - - if (items.size() > 27) { - GuiSize = 54; - backButton = 45; - } - - if (items.size() > 36) { - GuiSize = 54; - backButton = 53; - } - - if (items.size() > 45) { - GuiSize = 54; - backButton = 53; - } - - Inventory GuiInv = Bukkit.createInventory(null, GuiSize, job.getName() + " Info!"); - - for (int i1 = 0; i1 < items.size(); i1++) { - GuiInv.setItem(i1, items.get(i1)); - } - - ItemStack skull = new ItemStack(Material.JACK_O_LANTERN, 1, (byte) 0); - - ItemMeta skullMeta = skull.getItemMeta(); - skullMeta.setDisplayName("<<< Back"); - - skull.setItemMeta(skullMeta); - - GuiInv.setItem(backButton, skull); - - GuiInfoList guiInfo = new GuiInfoList(player.getName()); - guiInfo.setJobInfo(true); - guiInfo.setbackButton(backButton); - GuiList.put(player.getName(), guiInfo); - - return GuiInv; - } -} +package com.gamingmesh.jobs.Gui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.JobsCommands; +import com.gamingmesh.jobs.config.ConfigManager; +import com.gamingmesh.jobs.container.ActionType; +import com.gamingmesh.jobs.container.Job; +import com.gamingmesh.jobs.container.JobInfo; +import com.gamingmesh.jobs.container.JobProgression; +import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.i18n.Language; +import com.gamingmesh.jobs.stuff.TranslateName; + +public class GuiTools { + + public static HashMap GuiList = new HashMap(); + + public static Inventory CreateJobsGUI(Player player) { + + ArrayList JobsList = new ArrayList(); + for (Job job : Jobs.getJobs()) { + if (ConfigManager.getJobsConfiguration().getHideJobsWithoutPermission()) + if (!JobsCommands.hasJobPermission(player, job)) + continue; + JobsList.add(job); + } + + GuiInfoList guiInfo = new GuiInfoList(player.getName()); + guiInfo.setJobList(JobsList); + GuiList.put(player.getName(), guiInfo); + + int GuiSize = 9; + + if (JobsList.size() > 9) + GuiSize = 18; + + if (JobsList.size() > 18) + GuiSize = 27; + + if (JobsList.size() > 27) + GuiSize = 36; + + if (JobsList.size() > 36) + GuiSize = 45; + + if (JobsList.size() > 45) + GuiSize = 54; + + JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + + List pJobs = JPlayer.getJobProgression(); + + Inventory GuiInv = Bukkit.createInventory(null, GuiSize, "Pick your job!"); + + for (int i = 0; i < JobsList.size(); i++) { + + Job job = JobsList.get(i); + + ArrayList Lore = new ArrayList(); + + for (JobProgression onePJob : pJobs) { + if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) + Lore.add(Language.getMessage("command.info.gui.working")); + } + + int maxlevel = 0; + if (player.hasPermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0) + maxlevel = job.getVipMaxLevel(); + else + maxlevel = job.getMaxLevel(); + + if (maxlevel > 0) + Lore.add(Language.getMessage("command.info.gui.max") + maxlevel); + + if (ConfigManager.getJobsConfiguration().ShowTotalWorkers) + Lore.add(Language.getMessage("command.browse.output.totalWorkers").replace("[amount]", String.valueOf(job.getTotalPlayers()))); + + if (ConfigManager.getJobsConfiguration().useDynamicPayment && ConfigManager.getJobsConfiguration().ShowPenaltyBonus) + if (job.getBonus() < 0) + Lore.add(Language.getMessage("command.browse.output.penalty").replace("[amount]", String.valueOf((int) (job.getBonus() * 100) / 100.0 * -1))); + else + Lore.add(Language.getMessage("command.browse.output.bonus").replace("[amount]", String.valueOf((int) (job.getBonus() * 100) / 100.0))); + + Lore.add(job.getDescription()); + + if (job.getMaxSlots() != null) + Lore.add(Language.getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs.getUsedSlots(job)) : 0)); + + Lore.add(Language.getMessage("command.info.gui.actions")); + for (ActionType actionType : ActionType.values()) { + List info = job.getJobInfo(actionType); + if (info != null && !info.isEmpty()) { + Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); + } + } + + Lore.add(""); + Lore.add(Language.getDefaultMessage("command.info.gui.leftClick")); + Lore.add(Language.getDefaultMessage("command.info.gui.rightClick")); + + ItemStack GuiItem = job.getGuiItem(); + + ItemMeta meta = GuiItem.getItemMeta(); + meta.setDisplayName(job.getName()); + meta.setLore(Lore); + GuiItem.setItemMeta(meta); + + GuiInv.setItem(i, GuiItem); + } + return GuiInv; + } + + public static Inventory CreateJobsSubGUI(Player player, Job job) { + + Inventory tempInv = Bukkit.createInventory(null, 54, ""); + + ItemStack GuiItem = job.getGuiItem(); + JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + + // money exp boost + Player dude = Bukkit.getServer().getPlayer(player.getUniqueId()); + Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job); + Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job); + + int level = 1; + JobProgression prog = JPlayer.getJobProgression(job); + if (prog != null) + level = prog.getLevel(); + + int numjobs = JPlayer.getJobProgression().size(); + + List items = new ArrayList(); + int i = 0; + for (ActionType actionType : ActionType.values()) { + List info = job.getJobInfo(actionType); + + if (info == null || info.isEmpty()) + continue; + + ArrayList Lore = new ArrayList(); + Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); + int y = 1; + for (int z = 0; z < info.size(); z++) { + String itemName = TranslateName.Translate(info.get(z).getName(), info.get(z)); + + double income = info.get(z).getIncome(level, numjobs); + income = income + ((income * MoneyBoost) - income) + ((income * job.getMoneyBoost()) - income); + ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED; + + double xp = info.get(z).getExperience(level, numjobs); + xp = xp + ((xp * ExpBoost) - xp) + ((xp * job.getExpBoost()) - xp); + ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY; + + String xpString = String.format("%.2fxp", xp); + + Lore.add(ChatColor.translateAlternateColorCodes('&', "&7" + itemName + " " + xpColor + xpString + " " + incomeColor + Jobs.getEconomy().format(income))); + + if (y >= 10) { + y = 1; + + if (z == info.size() - 1) + continue; + ItemMeta meta = GuiItem.getItemMeta(); + meta.setDisplayName(job.getName()); + meta.setLore(Lore); + GuiItem.setItemMeta(meta); + //GuiInv.setItem(i, GuiItem); + tempInv.setItem(i, GuiItem); + + GuiItem = job.getGuiItem(); + Lore = new ArrayList(); + Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); + i++; + } + y++; + } + ItemMeta meta = GuiItem.getItemMeta(); + meta.setDisplayName(job.getName()); + meta.setLore(Lore); + GuiItem.setItemMeta(meta); + //GuiInv.setItem(i, GuiItem); + tempInv.setItem(i, GuiItem); + i++; + } + + for (ItemStack one : tempInv.getContents()) { + if (one != null) + items.add(one); + } + + int GuiSize = 18; + int backButton = 9; + + if (items.size() > 9) { + GuiSize = 27; + backButton = 18; + } + + if (items.size() > 18) { + GuiSize = 36; + backButton = 27; + } + + if (items.size() > 27) { + GuiSize = 45; + backButton = 36; + } + + if (items.size() > 36) { + GuiSize = 54; + backButton = 45; + } + +// if (items.size() > 45) { +// GuiSize = 54; +// backButton = 53; +// } + + Inventory GuiInv = Bukkit.createInventory(null, GuiSize, job.getName() + " Info!"); + + for (int i1 = 0; i1 < items.size(); i1++) { + GuiInv.setItem(i1, items.get(i1)); + } + + ItemStack skull = new ItemStack(Material.JACK_O_LANTERN, 1, (byte) 0); + + ItemMeta skullMeta = skull.getItemMeta(); + skullMeta.setDisplayName("<<< Back"); + + skull.setItemMeta(skullMeta); + + GuiInv.setItem(backButton, skull); + + GuiInfoList guiInfo = new GuiInfoList(player.getName()); + guiInfo.setJobInfo(true); + guiInfo.setbackButton(backButton); + GuiList.put(player.getName(), guiInfo); + + return GuiInv; + } +} diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java index 7e75783e..3ed51d02 100644 --- a/com/gamingmesh/jobs/JobsPlugin.java +++ b/com/gamingmesh/jobs/JobsPlugin.java @@ -19,6 +19,7 @@ package com.gamingmesh.jobs; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtectAPI; @@ -50,9 +51,51 @@ public class JobsPlugin extends JavaPlugin { public static CoreProtectAPI CPAPI; public static MythicMobsAPI MMAPI; public static boolean CPPresent = false; + private static NMS nms; + + public static NMS getNms() { + return nms; + } @Override public void onEnable() { + + String packageName = getServer().getClass().getPackage().getName(); + + String[] packageSplit = packageName.split("\\."); + String version = packageSplit[packageSplit.length - 1].split("(?<=\\G.{4})")[0]; + try { + Class nmsClass; + nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + version); + if (NMS.class.isAssignableFrom(nmsClass)) { + nms = (NMS) nmsClass.getConstructor().newInstance(); + } else { + System.out.println("Something went wrong, please note down version and contact author v:" + version); + this.setEnabled(false); + } + } catch (ClassNotFoundException e) { + System.out.println("Your server version is not compatible with this plugins version! Plugin will be disabled: " + version); + this.setEnabled(false); + } catch (InstantiationException e) { + e.printStackTrace(); + this.setEnabled(false); + } catch (IllegalAccessException e) { + e.printStackTrace(); + this.setEnabled(false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + this.setEnabled(false); + } catch (InvocationTargetException e) { + e.printStackTrace(); + this.setEnabled(false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + this.setEnabled(false); + } catch (SecurityException e) { + e.printStackTrace(); + this.setEnabled(false); + } + instance = this; OfflinePlayerList.fillList(); YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); diff --git a/com/gamingmesh/jobs/NMS.java b/com/gamingmesh/jobs/NMS.java new file mode 100644 index 00000000..10e73cc0 --- /dev/null +++ b/com/gamingmesh/jobs/NMS.java @@ -0,0 +1,13 @@ +package com.gamingmesh.jobs; + +import java.util.List; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.event.block.BlockPistonRetractEvent; + +public interface NMS { + + public List getPistonRetractBlocks(BlockPistonRetractEvent event); + + public boolean isElderGuardian(Entity entity); +} diff --git a/com/gamingmesh/jobs/actions/EntityActionInfo.java b/com/gamingmesh/jobs/actions/EntityActionInfo.java index d2ba59f2..0cda24d1 100644 --- a/com/gamingmesh/jobs/actions/EntityActionInfo.java +++ b/com/gamingmesh/jobs/actions/EntityActionInfo.java @@ -19,11 +19,11 @@ package com.gamingmesh.jobs.actions; import org.bukkit.entity.Entity; -import org.bukkit.entity.Guardian; import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Zombie; +import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.container.ActionInfo; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.BaseActionInfo; @@ -50,12 +50,8 @@ public class EntityActionInfo extends BaseActionInfo implements ActionInfo { return "ZombieVillager"; } - if (this.entity.getType().toString().toLowerCase().contains("guardian")) - if (this.entity instanceof Guardian) { - Guardian guardian = (Guardian) this.entity; - if (guardian.isElder()) - return "ElderGuardian"; - } + if (JobsPlugin.getNms().isElderGuardian(this.entity)) + return "ElderGuardian"; return entity.getType().toString(); } diff --git a/com/gamingmesh/jobs/commands/JobsCommands.java b/com/gamingmesh/jobs/commands/JobsCommands.java index 7bdd751c..4c287972 100644 --- a/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/com/gamingmesh/jobs/commands/JobsCommands.java @@ -1,5 +1,5 @@ /** - * Jobs Plugin for Bukkit + * Jobs Plugin for Bukkit * Copyright (C) 2011 Zak Ford * * This program is free software: you can redistribute it and/or modify @@ -224,11 +224,19 @@ public class JobsCommands implements CommandExecutor { if (!(sender instanceof Player)) return false; - if (args.length < 1) { + if (args.length != 1 && args.length != 0) { sendUsage(sender, "join"); return true; } + if (args.length == 0) { + if (sender instanceof Player && ConfigManager.getJobsConfiguration().JobsGUIOpenOnJoin) + ((Player) sender).openInventory(GuiTools.CreateJobsGUI((Player) sender)); + else + return false; + return true; + } + Player pSender = (Player) sender; JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); @@ -644,7 +652,7 @@ public class JobsCommands implements CommandExecutor { return true; } - if (sender instanceof Player) { + if (sender instanceof Player && ConfigManager.getJobsConfiguration().JobsGUIOpenOnBrowse) { ((Player) sender).openInventory(GuiTools.CreateJobsGUI((Player) sender)); } @@ -1374,8 +1382,8 @@ public class JobsCommands implements CommandExecutor { JobsPlayer JPlayer = null; if (args.length == 0) JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); - else if (args.length == 1 ) { - if (!sender.hasPermission("jobs.commands.log.others")){ + else if (args.length == 1) { + if (!sender.hasPermission("jobs.commands.log.others")) { sender.sendMessage(Language.getMessage("command.error.permission")); return true; } diff --git a/com/gamingmesh/jobs/config/JobsConfiguration.java b/com/gamingmesh/jobs/config/JobsConfiguration.java index cf89674f..eafd0965 100644 --- a/com/gamingmesh/jobs/config/JobsConfiguration.java +++ b/com/gamingmesh/jobs/config/JobsConfiguration.java @@ -87,7 +87,7 @@ public class JobsConfiguration { public boolean fixAtMaxLevel, ToggleActionBar, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAcountChat, EmptyServerAcountActionBar, JobsToggleEnabled, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, - useGlobalBoostScheduler; + useGlobalBoostScheduler, JobsGUIOpenOnBrowse,JobsGUIOpenOnJoin; public Integer levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume, SoundTitleChangePitch, ToplistInScoreboardInterval; public double BoostExp; @@ -625,6 +625,11 @@ public class JobsConfiguration { writer.addComment("JobsBrowse.ShowPenaltyBonus", "Do you want to show penalty and bonus in jobs browse window. Only works if this feature is enabled"); ShowPenaltyBonus = getBoolean("JobsBrowse.ShowPenaltyBonus", true, config, writer); + writer.addComment("JobsGUI.OpenOnBrowse", "Do you want to show GUI when performing /jobs browse command"); + JobsGUIOpenOnBrowse = getBoolean("JobsGUI.OpenOnBrowse", true, config, writer); + writer.addComment("JobsBrowse.ShowPenaltyBonus", "Do you want to show GUI when performing /jobs join command"); + JobsGUIOpenOnJoin = getBoolean("JobsGUI.OpenOnJoin", true, config, writer); + writer.addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost"); useGlobalBoostScheduler = getBoolean("Schedule.Boost.Enable", false, config, writer); @@ -1213,6 +1218,14 @@ public class JobsConfiguration { GetConfigString("command.info.help.actions", "&eValid actions are: &f%actions%", writer, conf, true); GetConfigString("command.info.help.max", " - &emax level:&f ", writer, conf, true); GetConfigString("command.info.help.material", "&7%material%", writer, conf, true); + + GetConfigString("command.info.gui.actions", "&eValid actions are:", writer, conf, true); + GetConfigString("command.info.gui.leftClick", "&eLeft Click for more info", writer, conf, true); + GetConfigString("command.info.gui.rightClick", "&eRight click to join job", writer, conf, true); + GetConfigString("command.info.gui.leftSlots", "&eLeft slots:&f ", writer, conf, true); + GetConfigString("command.info.gui.working", "&2&nAlready working", writer, conf, true); + GetConfigString("command.info.gui.max", "&eMax level:&f ", writer, conf, true); + GetConfigString("command.info.output.break.info", "Break", writer, conf, true); GetConfigString("command.info.output.break.none", "%jobname% does not get money for breaking blocks.", writer, conf, true); GetConfigString("command.info.output.place.info", "Place", writer, conf, true); diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java index 58e44ec4..c7d1412c 100644 --- a/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/com/gamingmesh/jobs/listeners/JobsListener.java @@ -65,37 +65,10 @@ public class JobsListener implements Listener { this.plugin = plugin; } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) - public void onGuiRightClick(InventoryClickEvent event) { - if (GuiTools.GuiList.size() == 0) - return; - - Player player = (Player) event.getWhoClicked(); - - if (!GuiTools.GuiList.containsKey(player.getName())) - return; - - if (event.getClick() != ClickType.RIGHT) - return; - - event.setCancelled(true); - - GuiInfoList joblist = GuiTools.GuiList.get(player.getName()); - - if (joblist.isJobInfo()) - return; - - int slot = event.getRawSlot(); - - if (slot < joblist.getJobList().size()) { - Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName()); - player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents()); - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) + @EventHandler(priority = EventPriority.LOWEST) public void onGuiLeftClick(InventoryClickEvent event) { - if (GuiTools.GuiList.size() == 0) + + if (GuiTools.GuiList.isEmpty()) return; Player player = (Player) event.getWhoClicked(); @@ -105,47 +78,27 @@ public class JobsListener implements Listener { event.setCancelled(true); - if (event.getClick() != ClickType.LEFT) - return; - GuiInfoList joblist = GuiTools.GuiList.get(player.getName()); - if (joblist.isJobInfo()) - return; - int slot = event.getRawSlot(); - if (slot < joblist.getJobList().size()) { - player.closeInventory(); - player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot))); - } - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) - public void onGuiLeftSubClick(InventoryClickEvent event) { - if (GuiTools.GuiList.size() == 0) - return; - - Player player = (Player) event.getWhoClicked(); - - if (!GuiTools.GuiList.containsKey(player.getName())) - return; - - event.setCancelled(true); - - if (event.getClick() != ClickType.LEFT) - return; - - GuiInfoList joblist = GuiTools.GuiList.get(player.getName()); - - if (!joblist.isJobInfo()) - return; - - int slot = event.getRawSlot(); - - if (slot == joblist.getbackButton()) { - player.closeInventory(); - player.openInventory(GuiTools.CreateJobsGUI(player)); + if (slot >= 0) { + if (event.getClick() == ClickType.LEFT) { + if (!joblist.isJobInfo() && slot < joblist.getJobList().size()) { + player.closeInventory(); + player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot))); + } else { + if (slot == joblist.getbackButton()) { + player.closeInventory(); + player.openInventory(GuiTools.CreateJobsGUI(player)); + } + } + } else if (event.getClick() == ClickType.RIGHT) { + if (!joblist.isJobInfo() && slot < joblist.getJobList().size()) { + Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName()); + player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents()); + } + } } } diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 604cb813..15606066 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -19,7 +19,6 @@ package com.gamingmesh.jobs.listeners; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -982,8 +981,7 @@ public class JobsPaymentListener implements Listener { double closest = 30.0; Player player = null; - Collection OnlinePLayers = Bukkit.getOnlinePlayers(); - for (Player i : OnlinePLayers) { + for (Player i : Bukkit.getOnlinePlayers()) { if (i.getWorld().getName().equals(animal.getWorld().getName())) { double dist = i.getLocation().distance(animal.getLocation()); if (closest > dist) { diff --git a/com/gamingmesh/jobs/listeners/PistonProtectionListener.java b/com/gamingmesh/jobs/listeners/PistonProtectionListener.java index 1ae995ca..88e52950 100644 --- a/com/gamingmesh/jobs/listeners/PistonProtectionListener.java +++ b/com/gamingmesh/jobs/listeners/PistonProtectionListener.java @@ -1,121 +1,121 @@ -package com.gamingmesh.jobs.listeners; - -import java.util.List; - -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; - -import com.gamingmesh.jobs.JobsPlugin; -import com.gamingmesh.jobs.config.ConfigManager; -import com.gamingmesh.jobs.i18n.Language; -import com.gamingmesh.jobs.stuff.ActionBar; - -public class PistonProtectionListener implements Listener { - - @SuppressWarnings("unused") - private JobsPlugin plugin; - - public PistonProtectionListener(JobsPlugin plugin) { - this.plugin = plugin; - } - - @SuppressWarnings("deprecation") - public static boolean CheckBlock(Block block) { - for (String BlockId : ConfigManager.getJobsConfiguration().restrictedBlocks) { - if (BlockId.equalsIgnoreCase(String.valueOf(block.getTypeId()))) { - return true; - } - } - return false; - } - - @SuppressWarnings("deprecation") - public static boolean CheckPlaceBlock(Block block) { - for (int BlockId : ConfigManager.getJobsConfiguration().restrictedPlaceBlocksTimer) { - if (BlockId == block.getTypeId()) { - return true; - } - } - return false; - } - - @SuppressWarnings("deprecation") - public static boolean CheckVegy(Block block) { - for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) { - int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]); - if (block.getTypeId() == ConfigPlacedBlockId) { - return true; - } - } - return false; - } - - @SuppressWarnings("deprecation") - public static boolean checkVegybreak(Block block, Player player) { - for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) { - int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]); - if (block.getTypeId() == ConfigPlacedBlockId) { - if (CheckVegyTimer(block, Integer.valueOf(ConfigOneBlock.split("-")[1]), player)) { - return true; - } - } - } - return false; - } - - public static boolean CheckVegyTimer(Block block, int time, Player player) { - long currentTime = System.currentTimeMillis(); - if (!block.hasMetadata(JobsPaymentListener.VegyMetadata)) - return false; - long BlockTime = block.getMetadata(JobsPaymentListener.VegyMetadata).get(0).asLong(); - - if (currentTime >= BlockTime + time * 1000) { - return false; - } - - int sec = Math.round((((BlockTime + time * 1000) - currentTime)) / 1000); - - ActionBar.send(player, Language.getMessage("message.blocktimer").replace("[time]", String.valueOf(sec))); - return true; - } - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public static void OnBlockMove(BlockPistonExtendEvent event) { - if (event.isCancelled()) - return; - - if (!ConfigManager.getJobsConfiguration().useBlockPiston) - return; - - List block = event.getBlocks(); - for (Block OneBlock : block) { - if (CheckBlock(OneBlock)) { - event.setCancelled(true); - break; - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void OnBlockRetractMove(BlockPistonRetractEvent event) { - - if (event.isCancelled()) - return; - - if (!ConfigManager.getJobsConfiguration().useBlockPiston) - return; - - List block = event.getBlocks(); - for (Block OneBlock : block) { - if (CheckBlock(OneBlock)) { - event.setCancelled(true); - break; - } - } - } -} +package com.gamingmesh.jobs.listeners; + +import java.util.List; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; + +import com.gamingmesh.jobs.JobsPlugin; +import com.gamingmesh.jobs.config.ConfigManager; +import com.gamingmesh.jobs.i18n.Language; +import com.gamingmesh.jobs.stuff.ActionBar; + +public class PistonProtectionListener implements Listener { + + @SuppressWarnings("unused") + private JobsPlugin plugin; + + public PistonProtectionListener(JobsPlugin plugin) { + this.plugin = plugin; + } + + @SuppressWarnings("deprecation") + public static boolean CheckBlock(Block block) { + for (String BlockId : ConfigManager.getJobsConfiguration().restrictedBlocks) { + if (BlockId.equalsIgnoreCase(String.valueOf(block.getTypeId()))) { + return true; + } + } + return false; + } + + @SuppressWarnings("deprecation") + public static boolean CheckPlaceBlock(Block block) { + for (int BlockId : ConfigManager.getJobsConfiguration().restrictedPlaceBlocksTimer) { + if (BlockId == block.getTypeId()) { + return true; + } + } + return false; + } + + @SuppressWarnings("deprecation") + public static boolean CheckVegy(Block block) { + for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) { + int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]); + if (block.getTypeId() == ConfigPlacedBlockId) { + return true; + } + } + return false; + } + + @SuppressWarnings("deprecation") + public static boolean checkVegybreak(Block block, Player player) { + for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) { + int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]); + if (block.getTypeId() == ConfigPlacedBlockId) { + if (CheckVegyTimer(block, Integer.valueOf(ConfigOneBlock.split("-")[1]), player)) { + return true; + } + } + } + return false; + } + + public static boolean CheckVegyTimer(Block block, int time, Player player) { + long currentTime = System.currentTimeMillis(); + if (!block.hasMetadata(JobsPaymentListener.VegyMetadata)) + return false; + long BlockTime = block.getMetadata(JobsPaymentListener.VegyMetadata).get(0).asLong(); + + if (currentTime >= BlockTime + time * 1000) { + return false; + } + + int sec = Math.round((((BlockTime + time * 1000) - currentTime)) / 1000); + + ActionBar.send(player, Language.getMessage("message.blocktimer").replace("[time]", String.valueOf(sec))); + return true; + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public static void OnBlockMove(BlockPistonExtendEvent event) { + if (event.isCancelled()) + return; + + if (!ConfigManager.getJobsConfiguration().useBlockPiston) + return; + + List block = event.getBlocks(); + for (Block OneBlock : block) { + if (CheckBlock(OneBlock)) { + event.setCancelled(true); + break; + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public static void OnBlockRetractMove(BlockPistonRetractEvent event) { + + if (event.isCancelled()) + return; + + if (!ConfigManager.getJobsConfiguration().useBlockPiston) + return; + + List block = JobsPlugin.getNms().getPistonRetractBlocks(event); + for (Block OneBlock : block) { + if (CheckBlock(OneBlock)) { + event.setCancelled(true); + break; + } + } + } +} diff --git a/com/gamingmesh/jobs/nmsUtil/.gitignore b/com/gamingmesh/jobs/nmsUtil/.gitignore new file mode 100644 index 00000000..b7b59cc6 --- /dev/null +++ b/com/gamingmesh/jobs/nmsUtil/.gitignore @@ -0,0 +1,2 @@ +/v1_8.class +/v1_7.class diff --git a/com/gamingmesh/jobs/nmsUtil/v1_7.java b/com/gamingmesh/jobs/nmsUtil/v1_7.java new file mode 100644 index 00000000..30d18033 --- /dev/null +++ b/com/gamingmesh/jobs/nmsUtil/v1_7.java @@ -0,0 +1,23 @@ +package com.gamingmesh.jobs.nmsUtil; + +import java.util.ArrayList; +import java.util.List; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.event.block.BlockPistonRetractEvent; + +import com.gamingmesh.jobs.NMS; + +public class v1_7 implements NMS { + @Override + public List getPistonRetractBlocks(BlockPistonRetractEvent event) { + List blocks = new ArrayList(); + blocks.add(event.getBlock()); + return blocks; + } + + @Override + public boolean isElderGuardian(Entity entity) { + return false; + } +} diff --git a/com/gamingmesh/jobs/nmsUtil/v1_8.java b/com/gamingmesh/jobs/nmsUtil/v1_8.java new file mode 100644 index 00000000..680dbf81 --- /dev/null +++ b/com/gamingmesh/jobs/nmsUtil/v1_8.java @@ -0,0 +1,30 @@ +package com.gamingmesh.jobs.nmsUtil; + +import java.util.ArrayList; +import java.util.List; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Guardian; +import org.bukkit.event.block.BlockPistonRetractEvent; + +import com.gamingmesh.jobs.NMS; + +public class v1_8 implements NMS { + @Override + public List getPistonRetractBlocks(BlockPistonRetractEvent event) { + List blocks = new ArrayList(); + blocks.addAll(event.getBlocks()); + return blocks; + } + + @Override + public boolean isElderGuardian(Entity entity) { + if (entity instanceof Guardian) { + Guardian guardian = (Guardian) entity; + if (guardian.isElder()) + return true; + } + return false; + } + +} diff --git a/jobConfig.yml b/jobConfig.yml index 52d16bf3..f01a05dc 100644 --- a/jobConfig.yml +++ b/jobConfig.yml @@ -54,6 +54,12 @@ Jobs: # joblevel - the level the player has attained in the job. # NOTE: Please take care of the brackets when modifying this equation. experience-progression-equation: baseexperience*((1.05)^(joblevel-1)) + # GUI icon information when using GUI function + Gui: + # id of block + Id: 17 + # data of block, usualy its 0, but in example Diorite will have id of 1 and data of 3 + Data: 2 ######################################################################## # Section used to configure what items the job gets paid for, how much # they get paid and how much experience they gain. diff --git a/plugin.yml b/plugin.yml index 19be53b7..5c9a6f5f 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.52.0 +version: 2.53.0 author: phrstbrn softdepend: [Vault, CoreProtect, MythicMobs, McMMO] commands: