mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 05:55:27 +01:00
GUI buttons to join and leave jobs directly
This commit is contained in:
parent
1b4d358100
commit
753edd7c9f
@ -21,6 +21,7 @@ import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
|
||||
import net.Zrips.CMILib.CMILib;
|
||||
import net.Zrips.CMILib.Colors.CMIChatColor;
|
||||
import net.Zrips.CMILib.Container.CMICommands;
|
||||
import net.Zrips.CMILib.GUI.CMIGui;
|
||||
import net.Zrips.CMILib.GUI.CMIGuiButton;
|
||||
@ -144,25 +145,40 @@ public class GuiManager {
|
||||
}
|
||||
|
||||
lore.add("");
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftClick"));
|
||||
|
||||
if (Jobs.getGCManager().JobsGUISwitcheButtons) {
|
||||
if (!jPlayer.isInJob(job)) {
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftClick"));
|
||||
}
|
||||
} else {
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftClick"));
|
||||
}
|
||||
|
||||
if (jPlayer.isInJob(job)) {
|
||||
if (Version.isCurrentEqualOrHigher(Version.v1_18_R1))
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.qClick"));
|
||||
else
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.middleClick"));
|
||||
}
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
|
||||
|
||||
ItemStack guiItem = job.getGuiItem();
|
||||
ItemMeta meta = guiItem.getItemMeta();
|
||||
meta.setDisplayName(job.getDisplayName());
|
||||
meta.setLore(lore);
|
||||
|
||||
if (Jobs.getGCManager().hideItemAttributes) {
|
||||
meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS);
|
||||
if (!Jobs.getGCManager().JobsGUISwitcheButtons) {
|
||||
if (!jPlayer.isInJob(job)) {
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
|
||||
}
|
||||
} else {
|
||||
lore.add(Jobs.getLanguage().getMessage("command.info.gui.rightClick"));
|
||||
}
|
||||
|
||||
guiItem.setItemMeta(meta);
|
||||
ItemStack guiItem = job.getGuiItem();
|
||||
// ItemMeta meta = guiItem.getItemMeta();
|
||||
// meta.setDisplayName(job.getDisplayName());
|
||||
// meta.setLore(lore);
|
||||
//
|
||||
// if (Jobs.getGCManager().hideItemAttributes) {
|
||||
// meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS);
|
||||
// }
|
||||
//
|
||||
// guiItem.setItemMeta(meta);
|
||||
|
||||
CMIGuiButton button = new CMIGuiButton(job.getGuiSlot() >= 0 ? job.getGuiSlot() : pos, guiItem) {
|
||||
|
||||
@ -206,6 +222,12 @@ public class GuiManager {
|
||||
}
|
||||
};
|
||||
|
||||
button.setName(job.getDisplayName());
|
||||
button.addLore(lore);
|
||||
if (Jobs.getGCManager().hideItemAttributes) {
|
||||
button.hideItemFlags();
|
||||
}
|
||||
|
||||
if (jPlayer.isInJob(job)) {
|
||||
button.setGlowing();
|
||||
}
|
||||
@ -288,15 +310,15 @@ public class GuiManager {
|
||||
double income = jInfo.getIncome(level, numjobs, jPlayer.maxJobsEquation);
|
||||
|
||||
income = boost.getFinalAmount(CurrencyType.MONEY, income);
|
||||
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
|
||||
String incomeColor = income >= 0 ? "" : CMIChatColor.DARK_RED.toString();
|
||||
|
||||
double xp = jInfo.getExperience(level, numjobs, jPlayer.maxJobsEquation);
|
||||
xp = boost.getFinalAmount(CurrencyType.EXP, xp);
|
||||
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
|
||||
String xpColor = xp >= 0 ? "" : CMIChatColor.GRAY.toString();
|
||||
|
||||
double points = jInfo.getPoints(level, numjobs, jPlayer.maxJobsEquation);
|
||||
points = boost.getFinalAmount(CurrencyType.POINTS, points);
|
||||
String pointsColor = points >= 0 ? "" : ChatColor.RED.toString();
|
||||
String pointsColor = points >= 0 ? "" : CMIChatColor.RED.toString();
|
||||
|
||||
if (income == 0D && points == 0D && xp == 0D)
|
||||
continue;
|
||||
@ -384,6 +406,24 @@ public class GuiManager {
|
||||
});
|
||||
}
|
||||
|
||||
if (!Jobs.getGCManager().DisableJoiningJobThroughGui) {
|
||||
if (jPlayer.isInJob(job)) {
|
||||
CMIGuiButton button = new CMIGuiButton(40, Jobs.getGCManager().guiLeaveButton) {
|
||||
@Override
|
||||
public void click(GUIClickType type) {
|
||||
leaveConfirmation(player, job, fromCommand, guiSize);
|
||||
}
|
||||
};
|
||||
button.setName(Jobs.getLanguage().getMessage("general.info.leave"));
|
||||
|
||||
gui.addButton(button);
|
||||
} else if (Jobs.getPlayerManager().getJobsLimit(jPlayer, (short) jPlayer.getJobProgression().size())) {
|
||||
gui.addButton(generateJoinButton(player, job, fromCommand, 39));
|
||||
gui.addButton(generateJoinButton(player, job, fromCommand, 40));
|
||||
gui.addButton(generateJoinButton(player, job, fromCommand, 41));
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= 53 && !jobsRemained.isEmpty()) {
|
||||
CMIItemStack next = CMILib.getInstance().getConfigManager().getGUINextPage();
|
||||
next.setDisplayName(LC.info_nextPageHover.getLocale());
|
||||
@ -400,6 +440,57 @@ public class GuiManager {
|
||||
gui.open();
|
||||
}
|
||||
|
||||
private void leaveConfirmation(Player player, Job job, boolean fromCommand, int guiSize) {
|
||||
|
||||
CMIGui gui = new CMIGui(player);
|
||||
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.jobinfo", "[jobname]", job.getName()));
|
||||
gui.setInvSize(guiSize);
|
||||
|
||||
gui.addButton(generateLeaveButton(player, job, fromCommand, 21));
|
||||
gui.addButton(generateLeaveButton(player, job, fromCommand, 22));
|
||||
gui.addButton(generateLeaveButton(player, job, fromCommand, 23));
|
||||
|
||||
CMIGuiButton button = new CMIGuiButton(40, Jobs.getGCManager().guiJoinButton) {
|
||||
@Override
|
||||
public void click(GUIClickType type) {
|
||||
openJobsBrowseGUI(player, job, fromCommand);
|
||||
}
|
||||
};
|
||||
button.setName(LC.modify_cancelSymbolHover.getLocale());
|
||||
gui.addButton(button);
|
||||
|
||||
gui.fillEmptyButtons();
|
||||
gui.open();
|
||||
}
|
||||
|
||||
private CMIGuiButton generateJoinButton(Player player, Job job, boolean fromCommand, int slot) {
|
||||
|
||||
CMIGuiButton button = new CMIGuiButton(slot, Jobs.getGCManager().guiJoinButton) {
|
||||
@Override
|
||||
public void click(GUIClickType type) {
|
||||
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "join", job.getName() });
|
||||
openJobsBrowseGUI(player, job, fromCommand);
|
||||
}
|
||||
};
|
||||
button.setName(Jobs.getLanguage().getMessage("general.info.join"));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private CMIGuiButton generateLeaveButton(Player player, Job job, boolean fromCommand, int slot) {
|
||||
|
||||
CMIGuiButton button = new CMIGuiButton(slot, Jobs.getGCManager().guiLeaveButton) {
|
||||
@Override
|
||||
public void click(GUIClickType type) {
|
||||
Jobs.getCommandManager().onCommand(player, null, "jobs", new String[] { "leave", job.getName() });
|
||||
openJobsBrowseGUI(player, job, fromCommand);
|
||||
}
|
||||
};
|
||||
button.setName(Jobs.getLanguage().getMessage("general.info.leave"));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private void openJobsBrowseGUI(Player player, Job job, List<ActionType> jobsRemained) {
|
||||
Inventory tempInv = Bukkit.createInventory(player, 54, "");
|
||||
|
||||
|
@ -116,6 +116,8 @@ public class GeneralConfigManager {
|
||||
public boolean DailyQuestsEnabled;
|
||||
|
||||
public ItemStack guiInfoButton;
|
||||
public ItemStack guiJoinButton;
|
||||
public ItemStack guiLeaveButton;
|
||||
public int InfoButtonSlot = 9;
|
||||
public List<String> InfoButtonCommands = new ArrayList<String>();
|
||||
|
||||
@ -1105,7 +1107,15 @@ public class GeneralConfigManager {
|
||||
CMIItemStack item = CMILib.getInstance().getItemManager().getItem(c.get("JobsGUI.InfoButton.Material",
|
||||
"head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjcwNWZkOTRhMGM0MzE5MjdmYjRlNjM5YjBmY2ZiNDk3MTdlNDEyMjg1YTAyYjQzOWUwMTEyZGEyMmIyZTJlYyJ9fX0="));
|
||||
guiInfoButton = item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.ARROW.newItemStack() : item.getItemStack();
|
||||
|
||||
|
||||
item = CMIItemStack.deserialize(c.get("JobsGUI.JoinButton.Material",
|
||||
"head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmZlYzNkMjVhZTBkMTQ3YzM0MmM0NTM3MGUwZTQzMzAwYTRlNDhhNWI0M2Y5YmI4NThiYWJmZjc1NjE0NGRhYyJ9fX0="));
|
||||
guiJoinButton = item == null || item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.GREEN_STAINED_GLASS_PANE.newItemStack() : item.getItemStack();
|
||||
|
||||
item = CMIItemStack.deserialize(c.get("JobsGUI.LeaveButton.Material",
|
||||
"head:eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzY1ZjNiYWUwZDIwM2JhMTZmZTFkYzNkMTMwN2E4NmE2MzhiZTkyNDQ3MWYyM2U4MmFiZDlkNzhmOGEzZmNhIn19fQ=="));
|
||||
guiLeaveButton = item == null || item.getCMIType() == CMIMaterial.NONE ? CMIMaterial.RED_STAINED_GLASS_PANE.newItemStack() : item.getItemStack();
|
||||
|
||||
c.addComment("JobsGUI.InfoButton.Commands", "closeinv! can be used to close players inventory when you click this icon");
|
||||
InfoButtonCommands = c.get("JobsGUI.InfoButton.Commands", Arrays.asList("closeinv!"));
|
||||
|
||||
|
@ -98,6 +98,10 @@ public class LanguageManager {
|
||||
c.get("general.info.blocks.smoker", "Smoker");
|
||||
c.get("general.info.blocks.blastfurnace", "Blast furnace");
|
||||
c.get("general.info.blocks.brewingstand", "Brewing stand");
|
||||
|
||||
c.get("general.info.join", "&eClick to join job");
|
||||
c.get("general.info.leave", "&cClick to leave job");
|
||||
|
||||
c.get("general.admin.error", "&cThere was an error in the command.");
|
||||
c.get("general.admin.success", "&eYour command has been performed.");
|
||||
c.get("general.error.noHelpPage", "&cThere is no help page by this number!");
|
||||
@ -111,6 +115,7 @@ public class LanguageManager {
|
||||
c.get("general.error.reenabledBlock", "&eReenabled ownership");
|
||||
c.get("general.error.noRegistration", "&cYou've reached max [block] count!");
|
||||
c.get("general.error.blockDisabled", "&6Payments from &e[type] &6got disabled. &2[location]");
|
||||
|
||||
|
||||
c.get("command.help.output.cmdUsage", "&2Usage: &7[command]");
|
||||
c.get("command.help.output.label", "Jobs");
|
||||
|
@ -77,7 +77,6 @@ import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEntityEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.inventory.AnvilInventory;
|
||||
import org.bukkit.inventory.EnchantingInventory;
|
||||
|
Loading…
Reference in New Issue
Block a user