1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +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

@ -19,6 +19,7 @@ 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.i18n.Language;
import com.gamingmesh.jobs.stuff.TranslateName; import com.gamingmesh.jobs.stuff.TranslateName;
public class GuiTools { public class GuiTools {
@ -70,7 +71,7 @@ public class GuiTools {
for (JobProgression onePJob : pJobs) { for (JobProgression onePJob : pJobs) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) if (onePJob.getJob().getName().equalsIgnoreCase(job.getName()))
Lore.add(ChatColor.translateAlternateColorCodes('&', "&2Working ")); Lore.add(Language.getMessage("command.info.gui.working"));
} }
int maxlevel = 0; int maxlevel = 0;
@ -80,23 +81,34 @@ public class GuiTools {
maxlevel = job.getMaxLevel(); maxlevel = job.getMaxLevel();
if (maxlevel > 0) if (maxlevel > 0)
Lore.add("Max level: " + maxlevel); 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()); Lore.add(job.getDescription());
if (job.getMaxSlots() != null) if (job.getMaxSlots() != null)
Lore.add("Left slots: " + (job.getMaxSlots() - Jobs.getUsedSlots(job))); Lore.add(Language.getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs.getUsedSlots(job)) : 0));
Lore.add(""); Lore.add(Language.getMessage("command.info.gui.actions"));
Lore.add("Posible actions");
for (ActionType actionType : ActionType.values()) { for (ActionType actionType : ActionType.values()) {
List<JobInfo> info = job.getJobInfo(actionType); List<JobInfo> info = job.getJobInfo(actionType);
if (info != null && !info.isEmpty()) { if (info != null && !info.isEmpty()) {
Lore.add(ChatColor.translateAlternateColorCodes('&', "&e" + actionType.getName())); 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(); ItemStack GuiItem = job.getGuiItem();
ItemMeta meta = GuiItem.getItemMeta(); ItemMeta meta = GuiItem.getItemMeta();
@ -121,7 +133,6 @@ public class GuiTools {
Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job); Double MoneyBoost = Jobs.getPlayerManager().GetMoneyBoost(dude, job);
Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job); Double ExpBoost = Jobs.getPlayerManager().GetExpBoost(dude, job);
int level = 1; int level = 1;
JobProgression prog = JPlayer.getJobProgression(job); JobProgression prog = JPlayer.getJobProgression(job);
if (prog != null) if (prog != null)
@ -188,33 +199,33 @@ public class GuiTools {
items.add(one); items.add(one);
} }
int GuiSize = 27; int GuiSize = 18;
int backButton = 18; int backButton = 9;
if (items.size() > 9) { if (items.size() > 9) {
GuiSize = 27;
backButton = 18;
}
if (items.size() > 18) {
GuiSize = 36; GuiSize = 36;
backButton = 27; backButton = 27;
} }
if (items.size() > 18) { if (items.size() > 27) {
GuiSize = 45; GuiSize = 45;
backButton = 36; backButton = 36;
} }
if (items.size() > 27) { if (items.size() > 36) {
GuiSize = 54; GuiSize = 54;
backButton = 45; backButton = 45;
} }
if (items.size() > 36) { // if (items.size() > 45) {
GuiSize = 54; // GuiSize = 54;
backButton = 53; // backButton = 53;
} // }
if (items.size() > 45) {
GuiSize = 54;
backButton = 53;
}
Inventory GuiInv = Bukkit.createInventory(null, GuiSize, job.getName() + " Info!"); Inventory GuiInv = Bukkit.createInventory(null, GuiSize, job.getName() + " Info!");

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) {
Guardian guardian = (Guardian) this.entity;
if (guardian.isElder())
return "ElderGuardian"; return "ElderGuardian";
}
return entity.getType().toString(); return entity.getType().toString();
} }

View File

@ -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,9 +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) { 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();
@ -75,77 +76,29 @@ public class JobsListener implements Listener {
if (!GuiTools.GuiList.containsKey(player.getName())) if (!GuiTools.GuiList.containsKey(player.getName()))
return; return;
if (event.getClick() != ClickType.RIGHT)
return;
event.setCancelled(true); event.setCancelled(true);
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) {
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()); Bukkit.dispatchCommand(player, "jobs join " + joblist.getJobList().get(slot).getName());
player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents()); player.getOpenInventory().getTopInventory().setContents(GuiTools.CreateJobsGUI(player).getContents());
} }
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onGuiLeftClick(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.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));
} }
} }

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

@ -110,7 +110,7 @@ public class PistonProtectionListener implements Listener {
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);

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: