1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Add files via upload

This commit is contained in:
LilBC 2021-07-01 14:34:27 -04:00 committed by GitHub
parent b01b90d0d0
commit 65070dc42e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners; package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
@ -8,13 +7,12 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.Event.Result; import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.entity.Player; import org.bukkit.inventory.Recipe;
import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
@ -22,7 +20,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.Abst
import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.EnhancedAutoCrafter; import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.EnhancedAutoCrafter;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Multimeter; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Multimeter;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import org.bukkit.inventory.Recipe;
import static org.bukkit.Bukkit.getRecipesFor;
/** /**
* This {@link Listener} is responsible for providing interactions to the auto crafters. * This {@link Listener} is responsible for providing interactions to the auto crafters.
@ -45,11 +44,8 @@ public class AutoCrafterListener implements Listener {
@EventHandler @EventHandler
public void onInteract(PlayerRightClickEvent e) { public void onInteract(PlayerRightClickEvent e) {
Optional<Block> clickedBlock = e.getClickedBlock(); Optional<Block> clickedBlock = e.getClickedBlock();
List<Recipe> recipes = org.bukkit.Bukkit.getRecipesFor(e.getItem());
Player p = e.getPlayer();
World w = p.getWorld();
NamespacedKey recipeKey; NamespacedKey recipeKey;
Boolean unlocked = true; boolean unlocked = true;
// We want to make sure we used the main hand, the interaction was not cancelled and a Block was clicked. // We want to make sure we used the main hand, the interaction was not cancelled and a Block was clicked.
if (e.getHand() == EquipmentSlot.HAND && e.useBlock() != Result.DENY && clickedBlock.isPresent()) { if (e.getHand() == EquipmentSlot.HAND && e.useBlock() != Result.DENY && clickedBlock.isPresent()) {
@ -71,16 +67,17 @@ public class AutoCrafterListener implements Listener {
} }
// Check if the recipe of the item is disabled. // Check if the recipe of the item is disabled.
for (Recipe recipe : recipes) { for (Recipe recipe : getRecipesFor(e.getItem())) {
recipeKey = ((Keyed) recipe).getKey(); recipeKey = ((Keyed) recipe).getKey();
if (!p.hasDiscoveredRecipe(recipeKey)) { if (!e.getPlayer().hasDiscoveredRecipe(recipeKey)) {
unlocked = false; unlocked = false;
break;
} }
} }
if (w.getGameRuleValue(GameRule.DO_LIMITED_CRAFTING) && !unlocked){ if (e.getPlayer().getWorld().getGameRuleValue(GameRule.DO_LIMITED_CRAFTING) && !unlocked) {
e.cancel(); e.cancel();
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-disabled"); SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.auto-crafting.recipe-disabled");
return; return;
} }