Prevent item place during brew obj, fixes #2096

This commit is contained in:
PikaMug 2023-04-25 19:47:55 -04:00
parent 7c30a0ce8e
commit ab0879d5a3

View File

@ -130,7 +130,8 @@ public class ItemListener implements Listener {
} }
} }
} else if (event.getInventory().getType() == InventoryType.BREWING) { } else if (event.getInventory().getType() == InventoryType.BREWING) {
if (event.getSlotType() == SlotType.CRAFTING) { if (event.getSlotType() == SlotType.CRAFTING
|| event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
final IQuester quester = plugin.getQuester(player.getUniqueId()); final IQuester quester = plugin.getQuester(player.getUniqueId());
final ObjectiveType type = ObjectiveType.BREW_ITEM; final ObjectiveType type = ObjectiveType.BREW_ITEM;
final Set<String> dispatchedQuestIDs = new HashSet<>(); final Set<String> dispatchedQuestIDs = new HashSet<>();
@ -141,13 +142,17 @@ public class ItemListener implements Listener {
if (quester.getCurrentQuestsTemp().containsKey(quest) if (quester.getCurrentQuestsTemp().containsKey(quest)
&& quester.getCurrentStage(quest).containsObjective(type)) { && quester.getCurrentStage(quest).containsObjective(type)) {
quester.brewItem(quest, event.getCurrentItem()); if (isAllowedBrewingAction(event)) {
quester.brewItem(quest, event.getCurrentItem());
}
} }
dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type, dispatchedQuestIDs.addAll(quester.dispatchMultiplayerEverything(quest, type,
(final IQuester q, final IQuest cq) -> { (final IQuester q, final IQuest cq) -> {
if (!dispatchedQuestIDs.contains(cq.getId())) { if (!dispatchedQuestIDs.contains(cq.getId())) {
q.brewItem(cq, event.getCurrentItem()); if (isAllowedBrewingAction(event)) {
q.brewItem(cq, event.getCurrentItem());
}
} }
return null; return null;
})); }));
@ -156,6 +161,25 @@ public class ItemListener implements Listener {
} }
} }
} }
public boolean isAllowedBrewingAction(final InventoryClickEvent event) {
final int slot = event.getRawSlot();
final InventoryAction action = event.getAction();
// Prevent shift-click into Brewing Stand
if (event.getSlotType() != SlotType.CRAFTING && action.equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
event.setCancelled(true);
return false;
}
// Prevent placing into Brewing Stand
if (slot == 0 || slot == 1 || slot == 2) {
if (action.equals(InventoryAction.PLACE_ONE) || action.equals(InventoryAction.PLACE_SOME)
|| action.equals(InventoryAction.PLACE_ALL)) {
event.setCancelled(true);
return false;
}
}
return true;
}
@EventHandler @EventHandler
public void onEnchantItem(final EnchantItemEvent event) { public void onEnchantItem(final EnchantItemEvent event) {
@ -198,7 +222,6 @@ public class ItemListener implements Listener {
} }
} }
@EventHandler @EventHandler
public void onConsumeItem(final PlayerItemConsumeEvent event) { public void onConsumeItem(final PlayerItemConsumeEvent event) {
if (event.isCancelled()) { if (event.isCancelled()) {