1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +01:00

Temporary fix for button click options

This commit is contained in:
montlikadani 2019-11-03 16:19:26 +01:00
parent 3a7eb65472
commit 4033ae1074
5 changed files with 105 additions and 35 deletions

View File

@ -17,18 +17,24 @@ import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.Reflections; import com.gamingmesh.jobs.CMILib.Reflections;
import com.gamingmesh.jobs.container.Job;
public class GUIListener implements Listener { public class GUIListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onNormalInventoryClose(InventoryCloseEvent event) { public void onNormalInventoryClose(InventoryCloseEvent event) {
final Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
if (GUIManager.isOpenedGui(player)) { if (GUIManager.isOpenedGui(player)) {
if (GUIManager.removePlayer(player)) { if (GUIManager.removePlayer(player)) {
player.updateInventory(); player.updateInventory();
clearIconItems(player); clearIconItems(player);
} }
if (Jobs.getGUIManager().isInGui(player)) {
Jobs.getGUIManager().GuiList.remove(player.getUniqueId());
}
} }
} }
@ -61,13 +67,14 @@ public class GUIListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) { public void onInventoryClick(final InventoryClickEvent event) {
final Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (!GUIManager.isOpenedGui(player)) if (!GUIManager.isOpenedGui(player))
return; return;
CMIGui gui = GUIManager.getGui(player); CMIGui gui = GUIManager.getGui(player);
if (event.getClick() == ClickType.DOUBLE_CLICK || event.getHotbarButton() != -1) { ClickType click = event.getClick();
if (click == ClickType.DOUBLE_CLICK || event.getHotbarButton() != -1) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -90,8 +97,10 @@ public class GUIListener implements Listener {
return; return;
} }
final List<Integer> buttons = new ArrayList<Integer>(); int slot = event.getRawSlot();
buttons.add(event.getRawSlot());
List<Integer> buttons = new ArrayList<Integer>();
buttons.add(slot);
if (!GUIManager.canClick(player, buttons)) { if (!GUIManager.canClick(player, buttons)) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -99,13 +108,15 @@ public class GUIListener implements Listener {
if (GUIManager.isLockedPart(player, buttons)) if (GUIManager.isLockedPart(player, buttons))
event.setCancelled(true); event.setCancelled(true);
InventoryAction action = event.getAction(); Job job = Jobs.getGUIManager().getJobBySlot(player, slot >= 0 ? slot : 0);
if (!GUIManager.processClick(player, event.getCurrentItem(), buttons, GUIManager.getClickType(event.isLeftClick(), event.isShiftClick(), action))) { if (!GUIManager.processClick(player, event.getCurrentItem(), buttons,
GUIManager.getClickType(event.isLeftClick(), event.isRightClick(), event.isShiftClick(), event.getAction()), job)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (gui.isAllowShift() && event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) && event.getClickedInventory().getType().equals(InventoryType.PLAYER)) { if (gui.isAllowShift() && event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) &&
event.getClickedInventory().getType().equals(InventoryType.PLAYER)) {
event.setCancelled(true); event.setCancelled(true);
@ -124,8 +135,8 @@ public class GUIListener implements Listener {
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryMove(final InventoryDragEvent event) { public void onInventoryMove(InventoryDragEvent event) {
final Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
if (!GUIManager.isOpenedGui(player)) if (!GUIManager.isOpenedGui(player))
return; return;
@ -135,7 +146,7 @@ public class GUIListener implements Listener {
return; return;
} }
final List<Integer> buttons = new ArrayList<Integer>(); List<Integer> buttons = new ArrayList<Integer>();
buttons.addAll(event.getRawSlots()); buttons.addAll(event.getRawSlots());
if (!GUIManager.canClick(player, buttons)) { if (!GUIManager.canClick(player, buttons)) {
event.setCancelled(true); event.setCancelled(true);
@ -145,10 +156,9 @@ public class GUIListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
if (!GUIManager.processClick(player, null, buttons, GUIManager.getClickType(true, false, null))) { if (!GUIManager.processClick(player, null, buttons, GUIManager.getClickType(true, false, false, null), null)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
} }

View File

@ -17,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.Reflections; import com.gamingmesh.jobs.CMILib.Reflections;
import com.gamingmesh.jobs.container.Job;
public class GUIManager { public class GUIManager {
@ -163,11 +164,22 @@ public class GUIManager {
} }
} }
public static GUIClickType getClickType(boolean left, boolean shift, InventoryAction action) { public static GUIClickType getClickType(boolean left, boolean right, boolean shift, InventoryAction action) {
if (!left && !shift && (action.equals(InventoryAction.NOTHING) || action.equals(InventoryAction.CLONE_STACK))) if (!left && !shift && (action.equals(InventoryAction.NOTHING) || action.equals(InventoryAction.CLONE_STACK)))
return GUIClickType.MiddleMouse; return GUIClickType.MiddleMouse;
if (!Jobs.getGCManager().JobsGUISwitcheButtons && left ||
Jobs.getGCManager().JobsGUISwitcheButtons && right) {
return GUIClickType.Left;
} else if (!Jobs.getGCManager().JobsGUISwitcheButtons && right ||
Jobs.getGCManager().JobsGUISwitcheButtons && left) {
if (Jobs.getGCManager().UseInversedClickToLeave) {
return GUIClickType.Left;
}
return GUIClickType.Right;
}
if (left && !shift) { if (left && !shift) {
return GUIClickType.Left; return GUIClickType.Left;
} else if (left && shift) { } else if (left && shift) {
@ -179,20 +191,31 @@ public class GUIManager {
} }
} }
public static boolean processClick(final Player player, ItemStack currentItem, List<Integer> buttons, final GUIClickType clickType) { public static boolean processClick(final Player player, ItemStack currentItem, List<Integer> buttons, final GUIClickType clickType,
Job job) {
CMIGui gui = map.get(player.getUniqueId()); CMIGui gui = map.get(player.getUniqueId());
if (gui == null) if (gui == null)
return true; return true;
for (Integer one : buttons) { for (Integer one : buttons) {
final CMIGuiButton button = gui.getButtons().get(one);
if (!gui.click(one, clickType, currentItem)) if (!gui.click(one, clickType, currentItem))
return false; return false;
final CMIGuiButton button = gui.getButtons().get(one);
if (button == null) if (button == null)
continue; continue;
if (job != null) {
if (!Jobs.getGCManager().JobsGUISwitcheButtons && clickType.equals(GUIClickType.Right) ||
Jobs.getGCManager().JobsGUISwitcheButtons && clickType.equals(GUIClickType.Left)) {
if (Jobs.getGCManager().UseInversedClickToLeave) {
button.addCommand(GUIClickType.Left, "jobs leave " + job.getName());
} else {
button.addCommand(GUIClickType.Right, "jobs join " + job.getName());
}
}
}
boolean canClick = true; boolean canClick = true;
for (String oneC : button.getPermissions()) { for (String oneC : button.getPermissions()) {
if (!player.hasPermission(oneC)) if (!player.hasPermission(oneC))
@ -203,7 +226,6 @@ public class GUIManager {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), new Runnable() { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), new Runnable() {
@Override @Override
public void run() { public void run() {
for (GUIButtonCommand oneC : button.getCommands(clickType)) { for (GUIButtonCommand oneC : button.getCommands(clickType)) {
performCommand(player, oneC.getCommand(), oneC.getCommandType()); performCommand(player, oneC.getCommand(), oneC.getCommandType());
} }

View File

@ -0,0 +1,27 @@
package com.gamingmesh.jobs.Gui;
import java.util.HashMap;
import com.gamingmesh.jobs.container.Job;
public class GUIInfoList {
private String name;
private HashMap<Integer, Job> jobList = new HashMap<>();
public GUIInfoList(String name) {
this.name = name;
}
public String getName() {
return name;
}
public HashMap<Integer, Job> getJobList() {
return jobList;
}
public void addJob(int slot, Job job) {
jobList.put(slot, job);
}
}

View File

@ -2,7 +2,9 @@ package com.gamingmesh.jobs.Gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -27,8 +29,22 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class GuiManager { public class GuiManager {
public void openJobsBrowseGUI(Player player) { public HashMap<UUID, GUIInfoList> GuiList = new HashMap<>();
public boolean isInGui(Player player) {
return GuiList.containsKey(player.getUniqueId());
}
public GUIInfoList getGuiInfo(Player p) {
return GuiList.get(p.getUniqueId());
}
public Job getJobBySlot(Player player, int slot) {
GUIInfoList info = GuiList.get(player.getUniqueId());
return info.getJobList().get(slot);
}
public void openJobsBrowseGUI(Player player) {
ArrayList<Job> JobsList = new ArrayList<>(); ArrayList<Job> JobsList = new ArrayList<>();
for (Job job : Jobs.getJobs()) { for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission()) if (Jobs.getGCManager().getHideJobsWithoutPermission())
@ -37,8 +53,10 @@ public class GuiManager {
JobsList.add(job); JobsList.add(job);
} }
GUIInfoList guiInfo = new GUIInfoList(player.getName());
GuiList.put(player.getUniqueId(), guiInfo);
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
List<JobProgression> pJobs = JPlayer.getJobProgression();
CMIGui gui = new CMIGui(player); CMIGui gui = new CMIGui(player);
gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.pickjob")); gui.setTitle(Jobs.getLanguage().getMessage("command.info.gui.pickjob"));
@ -82,7 +100,7 @@ public class GuiManager {
ArrayList<String> Lore = new ArrayList<>(); ArrayList<String> Lore = new ArrayList<>();
for (JobProgression onePJob : pJobs) { for (JobProgression onePJob : JPlayer.getJobProgression()) {
if (onePJob.getJob().getName().equalsIgnoreCase(job.getName())) if (onePJob.getJob().getName().equalsIgnoreCase(job.getName()))
Lore.add(Jobs.getLanguage().getMessage("command.info.gui.working")); Lore.add(Jobs.getLanguage().getMessage("command.info.gui.working"));
} }
@ -131,11 +149,12 @@ public class GuiManager {
meta.setLore(Lore); meta.setLore(Lore);
GuiItem.setItemMeta(meta); GuiItem.setItemMeta(meta);
guiInfo.addJob(pos, job);
gui.addButton(new CMIGuiButton(pos, GuiItem) { gui.addButton(new CMIGuiButton(pos, GuiItem) {
@Override @Override
public void click(GUIClickType type) { public void click(GUIClickType type) {
switch (type) { switch (type) {
case Left: case Left:
case LeftShift: case LeftShift:
@ -156,7 +175,6 @@ public class GuiManager {
} }
}); });
i++; i++;
} }
gui.fillEmptyButtons(); gui.fillEmptyButtons();

View File

@ -879,9 +879,10 @@ public class JobsPlayer {
public void resetQuests(Job job) { public void resetQuests(Job job) {
for (QuestProgression oneQ : getQuestProgressions(job)) { for (QuestProgression oneQ : getQuestProgressions(job)) {
oneQ.setValidUntil(0l); oneQ.setValidUntil(0l);
for (java.util.Map.Entry<String, QuestObjective> obj : oneQ.getQuest().getObjectives().entrySet()) { for (Entry<String, QuestObjective> obj : oneQ.getQuest().getObjectives().entrySet()) {
oneQ.setAmountDone(obj.getValue(), 0); oneQ.setAmountDone(obj.getValue(), 0);
} }
setDoneQuests(0); setDoneQuests(0);
getQuestProgressions(job).clear(); getQuestProgressions(job).clear();
} }
@ -889,15 +890,7 @@ public class JobsPlayer {
public void resetQuests() { public void resetQuests() {
for (JobProgression one : getJobProgression()) { for (JobProgression one : getJobProgression()) {
for (QuestProgression oneQ : getQuestProgressions(one.getJob())) { resetQuests(one.getJob());
for (java.util.Map.Entry<String, QuestObjective> obj : oneQ.getQuest().getObjectives().entrySet()) {
oneQ.setAmountDone(obj.getValue(), 0);
}
oneQ.setValidUntil(0L);
}
setDoneQuests(0);
getQuestProgressions(one.getJob()).clear();
} }
} }