forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(crafter): prevent using sf item in crafter (#948)
- Loading branch information
1 parent
6f16a50
commit fdb765c
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ub/thebusybiscuit/slimefun4/implementation/listeners/crafting/VanillaCrafterListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting; | ||
|
||
import city.norain.slimefun4.compatibillty.VersionedEvent; | ||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; | ||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
import javax.annotation.Nonnull; | ||
import org.bukkit.block.Crafter; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.inventory.InventoryAction; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryMoveItemEvent; | ||
import org.bukkit.event.inventory.InventoryType; | ||
import org.bukkit.inventory.Inventory; | ||
|
||
public class VanillaCrafterListener implements SlimefunCraftingListener { | ||
public VanillaCrafterListener(@Nonnull Slimefun plugin) { | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@EventHandler(ignoreCancelled = true) | ||
public void onCrafter(InventoryClickEvent e) { | ||
Inventory clickedInventory = e.getClickedInventory(); | ||
Inventory topInventory = VersionedEvent.getTopInventory(e); | ||
|
||
if (clickedInventory != null | ||
&& topInventory.getType() == InventoryType.CRAFTER | ||
&& topInventory.getHolder() instanceof Crafter | ||
&& e.getWhoClicked() instanceof Player player) { | ||
|
||
if (e.getAction() == InventoryAction.HOTBAR_SWAP) { | ||
e.setCancelled(true); | ||
return; | ||
} | ||
|
||
if (clickedInventory.getType() == InventoryType.CRAFTER) { | ||
e.setCancelled(isCraftingUnallowed(SlimefunItem.getByItem(e.getCursor()))); | ||
} else { | ||
e.setCancelled(isCraftingUnallowed(SlimefunItem.getByItem(e.getCurrentItem()))); | ||
} | ||
|
||
if (e.getResult() == Event.Result.DENY) { | ||
Slimefun.getLocalization().sendMessage((Player) e.getWhoClicked(), "crafter.not-working", true); | ||
} | ||
} | ||
} | ||
|
||
@EventHandler | ||
public void hopperOnCrafter(InventoryMoveItemEvent e) { | ||
if (e.getDestination().getType() == InventoryType.CRAFTER && isCraftingUnallowed(e.getItem())) { | ||
e.setCancelled(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters