Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brewing Stand Support #7275

Open
wants to merge 9 commits into
base: dev/feature
Choose a base branch
from
29 changes: 14 additions & 15 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package ch.njol.skript.classes.data;

import java.time.Duration;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.InventoryUtils;
Expand All @@ -27,11 +18,6 @@
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import io.papermc.paper.event.entity.EntityMoveEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;
import org.bukkit.*;
import io.papermc.paper.event.player.*;
import org.bukkit.*;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -66,9 +52,13 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public final class BukkitEventValues {

public BukkitEventValues() {
Expand Down Expand Up @@ -1894,6 +1884,15 @@ public Block get(PlayerChangeBeaconEffectEvent event) {
}
}, EventValues.TIME_NOW);
}

// BrewEvent
EventValues.registerEventValue(BrewEvent.class, ItemStack[].class,
event -> event.getResults().toArray(new ItemStack[0])
);

// BrewingStandFuelEvent
EventValues.registerEventValue(BrewingStandFuelEvent.class, ItemStack.class, BrewingStandFuelEvent::getFuel);

}

}
58 changes: 58 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondBrewingConsume.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.BrewingStandFuelEvent;
import org.jetbrains.annotations.Nullable;

@Name("Brewing Will Consume Fuel")
@Description({
"Checks if the 'brewing fuel' event will consume fuel.",
"By making it not consume, it will keep the fuel item and still add fuel to the brewing stand."
})
@Examples({
"on brewing fuel:",
"\tif the brewing stand will consume the fuel:",
"\tmake the brewing stand not consume the fuel"
})
@Since("INSERT VERSION")
public class CondBrewingConsume extends Condition {

static {
Skript.registerCondition(CondBrewingConsume.class,
"[the] brewing stand will consume [the] fuel",
"[the] brewing stand (will not|won't) consume [the] fuel");
}

private boolean checkConsume;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!getParser().isCurrentEvent(BrewingStandFuelEvent.class)) {
Skript.error("The 'brewing will consume fuel' condition only be used in a 'brewing fuel' event.");
return false;
}
return true;
}

@Override
public boolean check(Event event) {
if (!(event instanceof BrewingStandFuelEvent brewingStandFuelEvent))
return false;
return brewingStandFuelEvent.isConsuming() == checkConsume;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "the brewing stand will " + (checkConsume ? "" : "not") + " consume the fuel";
}

}
58 changes: 58 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffBrewingConsume.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.BrewingStandFuelEvent;
import org.jetbrains.annotations.Nullable;

@Name("Consume Brewing Fuel")
@Description({
"Makes the brewing stand in the brewing fuel event consume its fuel.",
"By making it not consume the fuel, it will keep the fuel item and still add to the fuel level of the brewing stand."
})
@Examples({
"on brewing fuel:",
"make the brewing stand not consume the fuel"
})
@Since("INSERT VERSION")
public class EffBrewingConsume extends Effect {

static {
Skript.registerEffect(EffBrewingConsume.class,
"make [the] brewing stand consume [the] fuel",
"make [the] brewing stand not consume [the] fuel");
}

private boolean consume;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (!getParser().isCurrentEvent(BrewingStandFuelEvent.class)) {
Skript.error("The 'consume brewing fuel' effect only be used in a 'brewing fuel' event.");
return false;
}
consume = matchedPattern == 0;
return true;
}

@Override
protected void execute(Event event) {
if (!(event instanceof BrewingStandFuelEvent brewingStandFuelEvent))
return;
brewingStandFuelEvent.setConsuming(consume);
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make the brewing stand " + (consume ? "" : "not") + " consume the fuel";
}

}
122 changes: 75 additions & 47 deletions src/main/java/ch/njol/skript/events/EvtItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import org.bukkit.event.entity.ItemDespawnEvent;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
Expand All @@ -46,6 +43,9 @@
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.util.coll.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("deprecation")
public class EvtItem extends SkriptEvent {

Expand Down Expand Up @@ -100,11 +100,6 @@ public class EvtItem extends SkriptEvent {
.examples("on pick up:")
.since("<i>unknown</i> (before 2.1)");
}
// TODO brew event
// Skript.registerEvent("Brew", EvtItem.class, BrewEvent.class, "brew[ing] [[of] %itemtypes%]")
// .description("Called when a potion finished brewing.")
// .examples("on brew:")
// .since("2.0");
if (hasConsumeEvent) {
Skript.registerEvent("Consume", EvtItem.class, PlayerItemConsumeEvent.class, "[player] ((eat|drink)[ing]|consum(e|ing)) [[of] %-itemtypes%]")
.description("Called when a player is done eating/drinking something, e.g. an apple, bread, meat, milk or a potion.")
Expand Down Expand Up @@ -156,6 +151,25 @@ public class EvtItem extends SkriptEvent {
.since("2.8.0")
.requiredPlugins("Paper 1.16+");
}

Skript.registerEvent("Brewing Complete", EvtItem.class, BrewEvent.class, "brew[ed] [complete[d]|finish[ed]] [of %-itemtypes%]")
.description("Called when a brewing stand finishes brewing the ingredient and changes the potions.")
.examples(
"on brew:",
"\tbroadcast event-items",
"on brew complete of speed potion:"
)
.since("INSERT VERSION");

Skript.registerEvent("Brewing Fuel", EvtItem.class, BrewingStandFuelEvent.class, "brewing fuel[ed] [of %-itemtypes%]")
.description("Called when a brewing stand is about to use an item to increase its fuel level.")
.examples(
"on brewing fuel:",
"\tmake the brewing stand not consume fuel",
"on brewing fuel of blaze powder:"
)
.since("INSERT VERSION");

}

@Nullable
Expand All @@ -171,59 +185,73 @@ public boolean init(final Literal<?>[] args, final int matchedPattern, final Par
}

@Override
@SuppressWarnings("null")
public boolean check(final Event event) {
if (event instanceof ItemSpawnEvent) // To make 'last dropped item' possible.
EffSecSpawn.lastSpawned = ((ItemSpawnEvent) event).getEntity();
public boolean check(Event event) {
if (event instanceof ItemSpawnEvent itemSpawnEvent) // To make 'last dropped item' possible.
EffSecSpawn.lastSpawned = itemSpawnEvent.getEntity();
if (hasEntityPickupItemEvent && ((!entity && event instanceof EntityPickupItemEvent) || (entity && event instanceof PlayerPickupItemEvent)))
return false;
if ((!entity && event instanceof EntityDropItemEvent) || (entity && event instanceof PlayerDropItemEvent))
return false;
if (types == null)
return true;
final ItemStack itemStack;
if (event instanceof BlockDispenseEvent) {
itemStack = ((BlockDispenseEvent) event).getItem();
} else if (event instanceof ItemSpawnEvent) {
itemStack = ((ItemSpawnEvent) event).getEntity().getItemStack();
} else if (event instanceof PlayerDropItemEvent) {
itemStack = ((PlayerDropItemEvent) event).getItemDrop().getItemStack();
} else if (event instanceof EntityDropItemEvent) {
itemStack = ((EntityDropItemEvent) event).getItemDrop().getItemStack();
} else if (event instanceof CraftItemEvent) {
itemStack = ((CraftItemEvent) event).getRecipe().getResult();
} else if (hasPrepareCraftEvent && event instanceof PrepareItemCraftEvent) {
Recipe recipe = ((PrepareItemCraftEvent) event).getRecipe();
ItemStack itemStack = null;
List<ItemStack> itemStacks = new ArrayList<>();
if (event instanceof BlockDispenseEvent blockDispenseEvent) {
itemStack = blockDispenseEvent.getItem();
} else if (event instanceof ItemSpawnEvent itemSpawnEvent) {
itemStack = itemSpawnEvent.getEntity().getItemStack();
} else if (event instanceof PlayerDropItemEvent playerDropItemEvent) {
itemStack = playerDropItemEvent.getItemDrop().getItemStack();
} else if (event instanceof EntityDropItemEvent entityDropItemEvent) {
itemStack = entityDropItemEvent.getItemDrop().getItemStack();
} else if (event instanceof CraftItemEvent craftItemEvent) {
itemStack = craftItemEvent.getRecipe().getResult();
} else if (hasPrepareCraftEvent && event instanceof PrepareItemCraftEvent prepareItemCraftEvent) {
Recipe recipe = prepareItemCraftEvent.getRecipe();
if (recipe != null) {
itemStack = recipe.getResult();
} else {
return false;
}
} else if (HAS_PLAYER_STONECUTTER_RECIPE_SELECT_EVENT && event instanceof PlayerStonecutterRecipeSelectEvent) {
itemStack = ((PlayerStonecutterRecipeSelectEvent) event).getStonecuttingRecipe().getResult();
} else if (event instanceof EntityPickupItemEvent) {
itemStack = ((EntityPickupItemEvent) event).getItem().getItemStack();
} else if (event instanceof PlayerPickupItemEvent) {
itemStack = ((PlayerPickupItemEvent) event).getItem().getItemStack();
} else if (hasConsumeEvent && event instanceof PlayerItemConsumeEvent) {
itemStack = ((PlayerItemConsumeEvent) event).getItem();
// } else if (e instanceof BrewEvent)
// itemStack = ((BrewEvent) e).getContents().getContents()
} else if (event instanceof InventoryClickEvent) {
itemStack = ((InventoryClickEvent) event).getCurrentItem();
} else if (event instanceof ItemDespawnEvent) {
itemStack = ((ItemDespawnEvent) event).getEntity().getItemStack();
} else if (event instanceof ItemMergeEvent) {
itemStack = ((ItemMergeEvent) event).getTarget().getItemStack();
} else if (event instanceof InventoryMoveItemEvent) {
itemStack = ((InventoryMoveItemEvent) event).getItem();
} else if (HAS_PLAYER_STONECUTTER_RECIPE_SELECT_EVENT && event instanceof PlayerStonecutterRecipeSelectEvent playerStonecutterRecipeSelectEvent) {
itemStack = playerStonecutterRecipeSelectEvent.getStonecuttingRecipe().getResult();
} else if (event instanceof EntityPickupItemEvent entityPickupItemEvent) {
itemStack = entityPickupItemEvent.getItem().getItemStack();
} else if (event instanceof PlayerPickupItemEvent playerPickupItemEvent) {
itemStack = playerPickupItemEvent.getItem().getItemStack();
} else if (hasConsumeEvent && event instanceof PlayerItemConsumeEvent playerItemConsumeEvent) {
itemStack = playerItemConsumeEvent.getItem();
} else if (event instanceof BrewEvent brewEvent) {
itemStacks.addAll(brewEvent.getResults());
} else if (event instanceof InventoryClickEvent inventoryClickEvent) {
itemStack = inventoryClickEvent.getCurrentItem();
} else if (event instanceof ItemDespawnEvent itemDespawnEvent) {
itemStack = itemDespawnEvent.getEntity().getItemStack();
} else if (event instanceof ItemMergeEvent itemMergeEvent) {
itemStack = itemMergeEvent.getTarget().getItemStack();
} else if (event instanceof InventoryMoveItemEvent inventoryMoveItemEvent) {
itemStack = inventoryMoveItemEvent.getItem();
} else if (event instanceof BrewingStandFuelEvent brewingStandFuelEvent) {
itemStack = brewingStandFuelEvent.getFuel();
} else {
assert false;
return false;
}
if (itemStack == null)
return false;
return types.check(event, itemType -> itemType.isOfType(itemStack));

ItemStack finalItemStack = itemStack;

if (itemStack != null) {
return types.check(event, itemType -> itemType.isOfType(finalItemStack));
} else if (!itemStacks.isEmpty()) {
return types.check(event, itemType -> {
for (ItemStack itemStack1 : itemStacks) {
if (itemType.isOfType(itemStack1))
return true;
}
return false;
});
}
return false;
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,14 @@ public class SimpleEvents {
)
.since("INSERT VERSION");

Skript.registerEvent("Brewing Start", SimpleEvent.class, BrewingStartEvent.class, "brew[ing] start")
.description("Called when a brewing stand starts brewing.")
.examples(
"on brewing start:",
"set the brewing time to 1"
)
.since("INSERT VERSION");

}

}
Loading
Loading