Skip to content

Commit ffdcbbe

Browse files
committed
Fixed: Hacky fix for /uses furnace not hijacking clicks
Apply the same change from e409ab8 This is still considered a temporary fix and should be handled properly.
1 parent ed7c6cd commit ffdcbbe

File tree

1 file changed

+8
-5
lines changed
  • modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands

1 file changed

+8
-5
lines changed

modules/RoyalCommands/src/main/java/org/royaldev/royalcommands/rcommands/CmdUses.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.bukkit.inventory.FurnaceRecipe;
2525
import org.bukkit.inventory.Inventory;
2626
import org.bukkit.inventory.InventoryHolder;
27+
import org.bukkit.inventory.InventoryView;
2728
import org.bukkit.inventory.ItemStack;
2829
import org.bukkit.inventory.Recipe;
2930
import org.bukkit.inventory.RecipeChoice;
@@ -154,7 +155,8 @@ public void run() {
154155
if (!CmdUses.this.tasks.containsKey(p.getName())) return;
155156
if (this.currentRecipe >= workbenches.size()) this.currentRecipe = 0;
156157
this.setClosing(true);
157-
p.openInventory(workbenches.get(this.currentRecipe));
158+
InventoryView iv = p.openInventory(workbenches.get(this.currentRecipe));
159+
iv.setTitle("Use: " + iv.getOriginalTitle());
158160
this.setClosing(false);
159161
this.currentRecipe++;
160162
if (workbenches.size() == 1) this.display = false;
@@ -220,8 +222,8 @@ public void workbenchClick(final InventoryClickEvent e) {
220222
final ItemStack is = e.getCurrentItem();
221223
if (is == null || is.getType() == Material.AIR) return;
222224
final InventoryType it = e.getInventory().getType();
223-
if (it != InventoryType.WORKBENCH && it != InventoryType.FURNACE) return;
224-
if (!(e.getInventory().getHolder() instanceof UsesHolder)) return;
225+
if (it.compareTo(InventoryType.WORKBENCH) != 0 && it.compareTo(InventoryType.FURNACE) != 0) return;
226+
if (!(e.getView().getTitle().startsWith("Use:"))) return;
225227
e.setCancelled(true);
226228
if (!(e.getWhoClicked() instanceof Player)) return;
227229
final Player p = (Player) e.getWhoClicked();
@@ -233,15 +235,16 @@ public void workbenchClose(final InventoryCloseEvent e) {
233235
if (!(e.getPlayer() instanceof Player)) return;
234236
final Player p = (Player) e.getPlayer();
235237
final InventoryType it = e.getInventory().getType();
236-
if (it != InventoryType.WORKBENCH && it != InventoryType.FURNACE) return;
238+
if (it.compareTo(InventoryType.WORKBENCH) != 0 && it.compareTo(InventoryType.FURNACE) != 0) return;
237239
if (!CmdUses.this.tasks.containsKey(p.getName())) return;
238-
if (!(e.getInventory().getHolder() instanceof UsesHolder)) return;
240+
if (!(e.getView().getTitle().startsWith("Recipe:"))) return;
239241
final UsesHolder uh = (UsesHolder) e.getInventory().getHolder();
240242
if (uh.isClosing()) return;
241243
CmdUses.this.cancelTask(p);
242244
}
243245
}
244246

247+
// TODO Remove UsesHolder entirely, not recommended these days
245248
private class UsesHolder implements InventoryHolder {
246249

247250
private boolean closing = false;

0 commit comments

Comments
 (0)