1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

GUI and 1.7 support

This commit is contained in:
Zrips 2015-11-27 16:34:19 +02:00
parent 254900c79a
commit 43abccf7d7
15 changed files with 543 additions and 446 deletions

View File

@ -5,3 +5,4 @@
/PlayerManager.class /PlayerManager.class
/Jobs$1.class /Jobs$1.class
/PlayerManager$1.class /PlayerManager$1.class
/NMS.class

View File

@ -1,241 +1,252 @@
package com.gamingmesh.jobs.Gui; package com.gamingmesh.jobs.Gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.JobsCommands; import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.ConfigManager;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.TranslateName; import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.stuff.TranslateName;
public class GuiTools {
public class GuiTools {
public static HashMap<String, GuiInfoList> GuiList = new HashMap<String, GuiInfoList>();
public static HashMap<String, GuiInfoList> GuiList = new HashMap<String, GuiInfoList>();
public static Inventory CreateJobsGUI(Player player) {
public static Inventory CreateJobsGUI(Player player) {
ArrayList<Job> JobsList = new ArrayList<Job>();
for (Job job : Jobs.getJobs()) { ArrayList<Job> JobsList = new ArrayList<Job>();
if (ConfigManager.getJobsConfiguration().getHideJobsWithoutPermission()) for (Job job : Jobs.getJobs()) {
if (!JobsCommands.hasJobPermission(player, job)) if (ConfigManager.getJobsConfiguration().getHideJobsWithoutPermission())
continue; if (!JobsCommands.hasJobPermission(player, job))
JobsList.add(job); continue;
} JobsList.add(job);
}
GuiInfoList guiInfo = new GuiInfoList(player.getName());
guiInfo.setJobList(JobsList); GuiInfoList guiInfo = new GuiInfoList(player.getName());
GuiList.put(player.getName(), guiInfo); guiInfo.setJobList(JobsList);
GuiList.put(player.getName(), guiInfo);
int GuiSize = 9;
int GuiSize = 9;
if (JobsList.size() > 9)
GuiSize = 18; if (JobsList.size() > 9)
GuiSize = 18;
if (JobsList.size() > 18)
GuiSize = 27; if (JobsList.size() > 18)
GuiSize = 27;
if (JobsList.size() > 27)
GuiSize = 36; if (JobsList.size() > 27)
GuiSize = 36;
if (JobsList.size() > 36)
GuiSize = 45; if (JobsList.size() > 36)
GuiSize = 45;
if (JobsList.size() > 45)
GuiSize = 54; if (JobsList.size() > 45)
GuiSize = 54;
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
List<JobProgression> pJobs = JPlayer.getJobProgression();
List<JobProgression> pJobs = JPlayer.getJobProgression();
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, "Pick your job!");
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, "Pick your job!");
for (int i = 0; i < JobsList.size(); i++) {
for (int i = 0; i < JobsList.size(); i++) {
Job job = JobsList.get(i);
Job job = JobsList.get(i);
ArrayList<String> Lore = new ArrayList<String>();
ArrayList<String> Lore = new ArrayList<String>();
for (JobProgression onePJob : pJobs) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) for (JobProgression onePJob : pJobs) {
Lore.add(ChatColor.translateAlternateColorCodes('&', "&2Working ")); 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) int maxlevel = 0;
maxlevel = job.getVipMaxLevel(); if (player.hasPermission("jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
else maxlevel = job.getVipMaxLevel();
maxlevel = job.getMaxLevel(); else
maxlevel = job.getMaxLevel();
if (maxlevel > 0)
Lore.add("Max level: " + maxlevel); if (maxlevel > 0)
Lore.add(Language.getMessage("command.info.gui.max") + maxlevel);
Lore.add(job.getDescription());
if (ConfigManager.getJobsConfiguration().ShowTotalWorkers)
if (job.getMaxSlots() != null) Lore.add(Language.getMessage("command.browse.output.totalWorkers").replace("[amount]", String.valueOf(job.getTotalPlayers())));
Lore.add("Left slots: " + (job.getMaxSlots() - Jobs.getUsedSlots(job)));
if (ConfigManager.getJobsConfiguration().useDynamicPayment && ConfigManager.getJobsConfiguration().ShowPenaltyBonus)
Lore.add(""); if (job.getBonus() < 0)
Lore.add("Posible actions"); Lore.add(Language.getMessage("command.browse.output.penalty").replace("[amount]", String.valueOf((int) (job.getBonus() * 100) / 100.0 * -1)));
for (ActionType actionType : ActionType.values()) { else
List<JobInfo> info = job.getJobInfo(actionType); Lore.add(Language.getMessage("command.browse.output.bonus").replace("[amount]", String.valueOf((int) (job.getBonus() * 100) / 100.0)));
if (info != null && !info.isEmpty()) { Lore.add(job.getDescription());
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName()));
} if (job.getMaxSlots() != null)
} Lore.add(Language.getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs.getUsedSlots(job)) : 0));
ItemStack GuiItem = job.getGuiItem(); Lore.add(Language.getMessage("command.info.gui.actions"));
for (ActionType actionType : ActionType.values()) {
ItemMeta meta = GuiItem.getItemMeta(); List<JobInfo> info = job.getJobInfo(actionType);
meta.setDisplayName(job.getName()); if (info != null && !info.isEmpty()) {
meta.setLore(Lore); Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName()));
GuiItem.setItemMeta(meta); }
}
GuiInv.setItem(i, GuiItem);
} Lore.add("");
return GuiInv; Lore.add(Language.getDefaultMessage("command.info.gui.leftClick"));
} Lore.add(Language.getDefaultMessage("command.info.gui.rightClick"));
public static Inventory CreateJobsSubGUI(Player player, Job job) { ItemStack GuiItem = job.getGuiItem();
Inventory tempInv = Bukkit.createInventory(null, 54, ""); ItemMeta meta = GuiItem.getItemMeta();
meta.setDisplayName(job.getName());
ItemStack GuiItem = job.getGuiItem(); meta.setLore(Lore);
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); GuiItem.setItemMeta(meta);
// money exp boost GuiInv.setItem(i, GuiItem);
Player dude = Bukkit.getServer().getPlayer(player.getUniqueId()); }
Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job); return GuiInv;
Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job); }
public static Inventory CreateJobsSubGUI(Player player, Job job) {
int level = 1;
JobProgression prog = JPlayer.getJobProgression(job); Inventory tempInv = Bukkit.createInventory(null, 54, "");
if (prog != null)
level = prog.getLevel(); ItemStack GuiItem = job.getGuiItem();
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
int numjobs = JPlayer.getJobProgression().size();
// money exp boost
List<ItemStack> items = new ArrayList<ItemStack>(); Player dude = Bukkit.getServer().getPlayer(player.getUniqueId());
int i = 0; Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job);
for (ActionType actionType : ActionType.values()) { Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job);
List<JobInfo> info = job.getJobInfo(actionType);
int level = 1;
if (info == null || info.isEmpty()) JobProgression prog = JPlayer.getJobProgression(job);
continue; if (prog != null)
level = prog.getLevel();
ArrayList<String> Lore = new ArrayList<String>();
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); int numjobs = JPlayer.getJobProgression().size();
int y = 1;
for (int z = 0; z < info.size(); z++) { List<ItemStack> items = new ArrayList<ItemStack>();
String itemName = TranslateName.Translate(info.get(z).getName(), info.get(z)); int i = 0;
for (ActionType actionType : ActionType.values()) {
double income = info.get(z).getIncome(level, numjobs); List<JobInfo> info = job.getJobInfo(actionType);
income = income + ((income * MoneyBoost) - income) + ((income * job.getMoneyBoost()) - income);
ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED; if (info == null || info.isEmpty())
continue;
double xp = info.get(z).getExperience(level, numjobs);
xp = xp + ((xp * ExpBoost) - xp) + ((xp * job.getExpBoost()) - xp); ArrayList<String> Lore = new ArrayList<String>();
ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY; Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName()));
int y = 1;
String xpString = String.format("%.2fxp", xp); for (int z = 0; z < info.size(); z++) {
String itemName = TranslateName.Translate(info.get(z).getName(), info.get(z));
Lore.add(ChatColor.translateAlternateColorCodes('&', "&7" + itemName + " " + xpColor + xpString + " " + incomeColor + Jobs.getEconomy().format(income)));
double income = info.get(z).getIncome(level, numjobs);
if (y >= 10) { income = income + ((income * MoneyBoost) - income) + ((income * job.getMoneyBoost()) - income);
y = 1; ChatColor incomeColor = income >= 0 ? ChatColor.GREEN : ChatColor.DARK_RED;
if (z == info.size() - 1) double xp = info.get(z).getExperience(level, numjobs);
continue; xp = xp + ((xp * ExpBoost) - xp) + ((xp * job.getExpBoost()) - xp);
ItemMeta meta = GuiItem.getItemMeta(); ChatColor xpColor = xp >= 0 ? ChatColor.YELLOW : ChatColor.GRAY;
meta.setDisplayName(job.getName());
meta.setLore(Lore); String xpString = String.format("%.2fxp", xp);
GuiItem.setItemMeta(meta);
//GuiInv.setItem(i, GuiItem); Lore.add(ChatColor.translateAlternateColorCodes('&', "&7" + itemName + " " + xpColor + xpString + " " + incomeColor + Jobs.getEconomy().format(income)));
tempInv.setItem(i, GuiItem);
if (y >= 10) {
GuiItem = job.getGuiItem(); y = 1;
Lore = new ArrayList<String>();
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); if (z == info.size() - 1)
i++; continue;
} ItemMeta meta = GuiItem.getItemMeta();
y++; meta.setDisplayName(job.getName());
} meta.setLore(Lore);
ItemMeta meta = GuiItem.getItemMeta(); GuiItem.setItemMeta(meta);
meta.setDisplayName(job.getName()); //GuiInv.setItem(i, GuiItem);
meta.setLore(Lore); tempInv.setItem(i, GuiItem);
GuiItem.setItemMeta(meta);
//GuiInv.setItem(i, GuiItem); GuiItem = job.getGuiItem();
tempInv.setItem(i, GuiItem); Lore = new ArrayList<String>();
i++; Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName()));
} i++;
}
for (ItemStack one : tempInv.getContents()) { y++;
if (one != null) }
items.add(one); ItemMeta meta = GuiItem.getItemMeta();
} meta.setDisplayName(job.getName());
meta.setLore(Lore);
int GuiSize = 27; GuiItem.setItemMeta(meta);
int backButton = 18; //GuiInv.setItem(i, GuiItem);
tempInv.setItem(i, GuiItem);
if (items.size() > 9) { i++;
GuiSize = 36; }
backButton = 27;
} for (ItemStack one : tempInv.getContents()) {
if (one != null)
if (items.size() > 18) { items.add(one);
GuiSize = 45; }
backButton = 36;
} int GuiSize = 18;
int backButton = 9;
if (items.size() > 27) {
GuiSize = 54; if (items.size() > 9) {
backButton = 45; GuiSize = 27;
} backButton = 18;
}
if (items.size() > 36) {
GuiSize = 54; if (items.size() > 18) {
backButton = 53; GuiSize = 36;
} backButton = 27;
}
if (items.size() > 45) {
GuiSize = 54; if (items.size() > 27) {
backButton = 53; GuiSize = 45;
} backButton = 36;
}
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, job.getName() + " Info!");
if (items.size() > 36) {
for (int i1 = 0; i1 < items.size(); i1++) { GuiSize = 54;
GuiInv.setItem(i1, items.get(i1)); backButton = 45;
} }
ItemStack skull = new ItemStack(Material.JACK_O_LANTERN, 1, (byte) 0); // if (items.size() > 45) {
// GuiSize = 54;
ItemMeta skullMeta = skull.getItemMeta(); // backButton = 53;
skullMeta.setDisplayName("<<< Back"); // }
skull.setItemMeta(skullMeta); Inventory GuiInv = Bukkit.createInventory(null, GuiSize, job.getName() + " Info!");
GuiInv.setItem(backButton, skull); for (int i1 = 0; i1 < items.size(); i1++) {
GuiInv.setItem(i1, items.get(i1));
GuiInfoList guiInfo = new GuiInfoList(player.getName()); }
guiInfo.setJobInfo(true);
guiInfo.setbackButton(backButton); ItemStack skull = new ItemStack(Material.JACK_O_LANTERN, 1, (byte) 0);
GuiList.put(player.getName(), guiInfo);
ItemMeta skullMeta = skull.getItemMeta();
return GuiInv; 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;
}
}

View File

@ -19,6 +19,7 @@
package com.gamingmesh.jobs; package com.gamingmesh.jobs;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI; import net.coreprotect.CoreProtectAPI;
@ -50,9 +51,51 @@ public class JobsPlugin extends JavaPlugin {
public static CoreProtectAPI CPAPI; public static CoreProtectAPI CPAPI;
public static MythicMobsAPI MMAPI; public static MythicMobsAPI MMAPI;
public static boolean CPPresent = false; public static boolean CPPresent = false;
private static NMS nms;
public static NMS getNms() {
return nms;
}
@Override @Override
public void onEnable() { 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; instance = this;
OfflinePlayerList.fillList(); OfflinePlayerList.fillList();
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");

View File

@ -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<Block> getPistonRetractBlocks(BlockPistonRetractEvent event);
public boolean isElderGuardian(Entity entity);
}

View File

@ -19,11 +19,11 @@
package com.gamingmesh.jobs.actions; package com.gamingmesh.jobs.actions;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.entity.Zombie; import org.bukkit.entity.Zombie;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.container.ActionInfo; import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BaseActionInfo; import com.gamingmesh.jobs.container.BaseActionInfo;
@ -50,12 +50,8 @@ public class EntityActionInfo extends BaseActionInfo implements ActionInfo {
return "ZombieVillager"; return "ZombieVillager";
} }
if (this.entity.getType().toString().toLowerCase().contains("guardian")) if (JobsPlugin.getNms().isElderGuardian(this.entity))
if (this.entity instanceof Guardian) { return "ElderGuardian";
Guardian guardian = (Guardian) this.entity;
if (guardian.isElder())
return "ElderGuardian";
}
return entity.getType().toString(); return entity.getType().toString();
} }

View File

@ -1,5 +1,5 @@
/** /**
* Jobs Plugin for Bukkit * Jobs Plugin for Bukkit
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com> * Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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)) if (!(sender instanceof Player))
return false; return false;
if (args.length < 1) { if (args.length != 1 && args.length != 0) {
sendUsage(sender, "join"); sendUsage(sender, "join");
return true; 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; Player pSender = (Player) sender;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
@ -644,7 +652,7 @@ public class JobsCommands implements CommandExecutor {
return true; return true;
} }
if (sender instanceof Player) { if (sender instanceof Player && ConfigManager.getJobsConfiguration().JobsGUIOpenOnBrowse) {
((Player) sender).openInventory(GuiTools.CreateJobsGUI((Player) sender)); ((Player) sender).openInventory(GuiTools.CreateJobsGUI((Player) sender));
} }
@ -1374,8 +1382,8 @@ public class JobsCommands implements CommandExecutor {
JobsPlayer JPlayer = null; JobsPlayer JPlayer = null;
if (args.length == 0) if (args.length == 0)
JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
else if (args.length == 1 ) { else if (args.length == 1) {
if (!sender.hasPermission("jobs.commands.log.others")){ if (!sender.hasPermission("jobs.commands.log.others")) {
sender.sendMessage(Language.getMessage("command.error.permission")); sender.sendMessage(Language.getMessage("command.error.permission"));
return true; return true;
} }

View File

@ -87,7 +87,7 @@ public class JobsConfiguration {
public boolean fixAtMaxLevel, ToggleActionBar, TitleChangeChat, TitleChangeActionBar, LevelChangeChat, public boolean fixAtMaxLevel, ToggleActionBar, TitleChangeChat, TitleChangeActionBar, LevelChangeChat,
LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAcountChat, LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAcountChat,
EmptyServerAcountActionBar, JobsToggleEnabled, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment, EmptyServerAcountActionBar, JobsToggleEnabled, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment,
useGlobalBoostScheduler; useGlobalBoostScheduler, JobsGUIOpenOnBrowse,JobsGUIOpenOnJoin;
public Integer levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume, public Integer levelLossPercentage, SoundLevelupVolume, SoundLevelupPitch, SoundTitleChangeVolume,
SoundTitleChangePitch, ToplistInScoreboardInterval; SoundTitleChangePitch, ToplistInScoreboardInterval;
public double BoostExp; 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"); 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); 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"); writer.addComment("Schedule.Boost.Enable", "Do you want to enable scheduler for global boost");
useGlobalBoostScheduler = getBoolean("Schedule.Boost.Enable", false, config, writer); 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.actions", "&eValid actions are: &f%actions%", writer, conf, true);
GetConfigString("command.info.help.max", " - &emax level:&f ", 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.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.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.break.none", "%jobname% does not get money for breaking blocks.", writer, conf, true);
GetConfigString("command.info.output.place.info", "Place", writer, conf, true); GetConfigString("command.info.output.place.info", "Place", writer, conf, true);

View File

@ -65,37 +65,10 @@ public class JobsListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOWEST)
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)
public void onGuiLeftClick(InventoryClickEvent event) { public void onGuiLeftClick(InventoryClickEvent event) {
if (GuiTools.GuiList.size() == 0)
if (GuiTools.GuiList.isEmpty())
return; return;
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
@ -105,47 +78,27 @@ public class JobsListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
if (event.getClick() != ClickType.LEFT)
return;
GuiInfoList joblist = GuiTools.GuiList.get(player.getName()); GuiInfoList joblist = GuiTools.GuiList.get(player.getName());
if (joblist.isJobInfo())
return;
int slot = event.getRawSlot(); int slot = event.getRawSlot();
if (slot < joblist.getJobList().size()) { if (slot >= 0) {
player.closeInventory(); if (event.getClick() == ClickType.LEFT) {
player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot))); if (!joblist.isJobInfo() && slot < joblist.getJobList().size()) {
} player.closeInventory();
} player.openInventory(GuiTools.CreateJobsSubGUI(player, joblist.getJobList().get(slot)));
} else {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) if (slot == joblist.getbackButton()) {
public void onGuiLeftSubClick(InventoryClickEvent event) { player.closeInventory();
if (GuiTools.GuiList.size() == 0) player.openInventory(GuiTools.CreateJobsGUI(player));
return; }
}
Player player = (Player) event.getWhoClicked(); } else if (event.getClick() == ClickType.RIGHT) {
if (!joblist.isJobInfo() && slot < joblist.getJobList().size()) {
if (!GuiTools.GuiList.containsKey(player.getName())) Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName());
return; player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents());
}
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));
} }
} }

View File

@ -19,7 +19,6 @@
package com.gamingmesh.jobs.listeners; package com.gamingmesh.jobs.listeners;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -982,8 +981,7 @@ public class JobsPaymentListener implements Listener {
double closest = 30.0; double closest = 30.0;
Player player = null; Player player = null;
Collection<? extends Player> OnlinePLayers = Bukkit.getOnlinePlayers(); for (Player i : Bukkit.getOnlinePlayers()) {
for (Player i : OnlinePLayers) {
if (i.getWorld().getName().equals(animal.getWorld().getName())) { if (i.getWorld().getName().equals(animal.getWorld().getName())) {
double dist = i.getLocation().distance(animal.getLocation()); double dist = i.getLocation().distance(animal.getLocation());
if (closest > dist) { if (closest > dist) {

View File

@ -1,121 +1,121 @@
package com.gamingmesh.jobs.listeners; package com.gamingmesh.jobs.listeners;
import java.util.List; import java.util.List;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.ConfigManager;
import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.ActionBar;
public class PistonProtectionListener implements Listener { public class PistonProtectionListener implements Listener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private JobsPlugin plugin; private JobsPlugin plugin;
public PistonProtectionListener(JobsPlugin plugin) { public PistonProtectionListener(JobsPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static boolean CheckBlock(Block block) { public static boolean CheckBlock(Block block) {
for (String BlockId : ConfigManager.getJobsConfiguration().restrictedBlocks) { for (String BlockId : ConfigManager.getJobsConfiguration().restrictedBlocks) {
if (BlockId.equalsIgnoreCase(String.valueOf(block.getTypeId()))) { if (BlockId.equalsIgnoreCase(String.valueOf(block.getTypeId()))) {
return true; return true;
} }
} }
return false; return false;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static boolean CheckPlaceBlock(Block block) { public static boolean CheckPlaceBlock(Block block) {
for (int BlockId : ConfigManager.getJobsConfiguration().restrictedPlaceBlocksTimer) { for (int BlockId : ConfigManager.getJobsConfiguration().restrictedPlaceBlocksTimer) {
if (BlockId == block.getTypeId()) { if (BlockId == block.getTypeId()) {
return true; return true;
} }
} }
return false; return false;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static boolean CheckVegy(Block block) { public static boolean CheckVegy(Block block) {
for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) { for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) {
int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]); int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]);
if (block.getTypeId() == ConfigPlacedBlockId) { if (block.getTypeId() == ConfigPlacedBlockId) {
return true; return true;
} }
} }
return false; return false;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static boolean checkVegybreak(Block block, Player player) { public static boolean checkVegybreak(Block block, Player player) {
for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) { for (String ConfigOneBlock : ConfigManager.getJobsConfiguration().restrictedBlocksTimer) {
int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]); int ConfigPlacedBlockId = Integer.valueOf(ConfigOneBlock.split("-")[0]);
if (block.getTypeId() == ConfigPlacedBlockId) { if (block.getTypeId() == ConfigPlacedBlockId) {
if (CheckVegyTimer(block, Integer.valueOf(ConfigOneBlock.split("-")[1]), player)) { if (CheckVegyTimer(block, Integer.valueOf(ConfigOneBlock.split("-")[1]), player)) {
return true; return true;
} }
} }
} }
return false; return false;
} }
public static boolean CheckVegyTimer(Block block, int time, Player player) { public static boolean CheckVegyTimer(Block block, int time, Player player) {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
if (!block.hasMetadata(JobsPaymentListener.VegyMetadata)) if (!block.hasMetadata(JobsPaymentListener.VegyMetadata))
return false; return false;
long BlockTime = block.getMetadata(JobsPaymentListener.VegyMetadata).get(0).asLong(); long BlockTime = block.getMetadata(JobsPaymentListener.VegyMetadata).get(0).asLong();
if (currentTime >= BlockTime + time * 1000) { if (currentTime >= BlockTime + time * 1000) {
return false; return false;
} }
int sec = Math.round((((BlockTime + time * 1000) - currentTime)) / 1000); int sec = Math.round((((BlockTime + time * 1000) - currentTime)) / 1000);
ActionBar.send(player, Language.getMessage("message.blocktimer").replace("[time]", String.valueOf(sec))); ActionBar.send(player, Language.getMessage("message.blocktimer").replace("[time]", String.valueOf(sec)));
return true; return true;
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public static void OnBlockMove(BlockPistonExtendEvent event) { public static void OnBlockMove(BlockPistonExtendEvent event) {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (!ConfigManager.getJobsConfiguration().useBlockPiston) if (!ConfigManager.getJobsConfiguration().useBlockPiston)
return; return;
List<Block> block = event.getBlocks(); List<Block> block = event.getBlocks();
for (Block OneBlock : block) { for (Block OneBlock : block) {
if (CheckBlock(OneBlock)) { if (CheckBlock(OneBlock)) {
event.setCancelled(true); event.setCancelled(true);
break; break;
} }
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void OnBlockRetractMove(BlockPistonRetractEvent event) { public static void OnBlockRetractMove(BlockPistonRetractEvent event) {
if (event.isCancelled()) if (event.isCancelled())
return; return;
if (!ConfigManager.getJobsConfiguration().useBlockPiston) if (!ConfigManager.getJobsConfiguration().useBlockPiston)
return; return;
List<Block> block = event.getBlocks(); List<Block> block = JobsPlugin.getNms().getPistonRetractBlocks(event);
for (Block OneBlock : block) { for (Block OneBlock : block) {
if (CheckBlock(OneBlock)) { if (CheckBlock(OneBlock)) {
event.setCancelled(true); event.setCancelled(true);
break; break;
} }
} }
} }
} }

View File

@ -0,0 +1,2 @@
/v1_8.class
/v1_7.class

View File

@ -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<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<Block>();
blocks.add(event.getBlock());
return blocks;
}
@Override
public boolean isElderGuardian(Entity entity) {
return false;
}
}

View File

@ -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<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
List<Block> blocks = new ArrayList<Block>();
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;
}
}

View File

@ -54,6 +54,12 @@ Jobs:
# joblevel - the level the player has attained in the job. # joblevel - the level the player has attained in the job.
# NOTE: Please take care of the brackets when modifying this equation. # NOTE: Please take care of the brackets when modifying this equation.
experience-progression-equation: baseexperience*((1.05)^(joblevel-1)) 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 # Section used to configure what items the job gets paid for, how much
# they get paid and how much experience they gain. # they get paid and how much experience they gain.

View File

@ -1,7 +1,7 @@
name: Jobs name: Jobs
description: Jobs Plugin for the BukkitAPI description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin main: com.gamingmesh.jobs.JobsPlugin
version: 2.52.0 version: 2.53.0
author: phrstbrn author: phrstbrn
softdepend: [Vault, CoreProtect, MythicMobs, McMMO] softdepend: [Vault, CoreProtect, MythicMobs, McMMO]
commands: commands: