Skip to content

Commit

Permalink
forbid item scripts in brewing
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 30, 2021
1 parent 8b11a74 commit c825ace
Showing 1 changed file with 30 additions and 0 deletions.
Expand Up @@ -25,6 +25,8 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockCookEvent;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.BrewingStandFuelEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.*;
Expand Down Expand Up @@ -499,4 +501,32 @@ public void onItemCooked(BlockCookEvent event) {
}
event.setCancelled(true);
}

public boolean isAllowedToCraftWith(ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
return true;
}
ItemScriptContainer container = getItemScriptContainer(item);
if (container == null) {
return true;
}
return container.allowInMaterialRecipes;
}

@EventHandler(priority = EventPriority.LOW)
public void onBrewingStandBrews(BrewEvent event) {
for (ItemStack item : event.getContents()) {
if (!isAllowedToCraftWith(item)) {
event.setCancelled(true);
return;
}
}
}

@EventHandler(priority = EventPriority.LOW)
public void onBrewingStandFuel(BrewingStandFuelEvent event) {
if (!isAllowedToCraftWith(event.getFuel())) {
event.setCancelled(true);
}
}
}

0 comments on commit c825ace

Please sign in to comment.