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

FurnaceEvents, Expressions #7093

Open
wants to merge 30 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
829e903
Starter Commit
TheAbsolutionism Sep 18, 2024
5869c75
More Commits
TheAbsolutionism Sep 18, 2024
c532d3d
Cleanup
TheAbsolutionism Sep 18, 2024
5e6d1f5
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Sep 19, 2024
18058fc
Chanages
TheAbsolutionism Sep 19, 2024
4419e88
Merge branch 'dev/FurnaceEvents' of https://github.com/TheAbsolutioni…
TheAbsolutionism Sep 19, 2024
ed3e310
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Sep 21, 2024
bd0fb12
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Sep 22, 2024
c62c1bc
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Sep 22, 2024
c163557
Requested Changes
TheAbsolutionism Sep 24, 2024
fbf8842
Syntax Fix
TheAbsolutionism Sep 26, 2024
077d8c3
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Oct 1, 2024
6fc4fc9
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Oct 2, 2024
cde2c53
Requested Changes
TheAbsolutionism Oct 2, 2024
449a95e
Merge branch 'dev/FurnaceEvents' of https://github.com/TheAbsolutioni…
TheAbsolutionism Oct 2, 2024
d64a1c6
Merge branch 'dev/feature' into dev/FurnaceEvents
sovdeeth Oct 3, 2024
abb17c6
Requested Changes
TheAbsolutionism Oct 4, 2024
3e919ab
Requested Changes
TheAbsolutionism Oct 12, 2024
e4c3eb7
Partial Changes
TheAbsolutionism Oct 12, 2024
d884d05
Requested Changes
TheAbsolutionism Oct 12, 2024
9bf22b0
Requested Changes
TheAbsolutionism Oct 15, 2024
6cb8a1a
Merge branch 'dev/feature' into dev/FurnaceEvents
sovdeeth Oct 15, 2024
4597da5
fix merge issues
sovdeeth Oct 15, 2024
1f9a1c1
Removed default case
TheAbsolutionism Oct 16, 2024
49acc83
Merge remote-tracking branch 'upstream/dev/feature' into dev/FurnaceE…
TheAbsolutionism Oct 27, 2024
7a60205
Requested Changes
TheAbsolutionism Oct 30, 2024
e5fd7a4
Module
TheAbsolutionism Oct 30, 2024
0c144c8
Merge remote-tracking branch 'upstream/dev/feature' into dev/FurnaceE…
TheAbsolutionism Nov 2, 2024
95b6307
Merge branch 'dev/feature' into dev/FurnaceEvents
TheAbsolutionism Nov 11, 2024
ecada30
Merge branch 'dev/feature' into dev/FurnaceEvents
Efnilite Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,7 @@
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.DragType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
Expand Down Expand Up @@ -1935,5 +1924,19 @@ public RegainReason get(EntityRegainHealthEvent event) {
return event.getRegainReason();
}
}, EventValues.TIME_NOW);

// FurnaceExtractEvent
EventValues.registerEventValue(FurnaceExtractEvent.class, Player.class, new Getter<Player, FurnaceExtractEvent>() {
@Override
public @Nullable Player get(FurnaceExtractEvent event) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return event.getPlayer();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(FurnaceExtractEvent.class, ItemStack[].class, new Getter<ItemStack[], FurnaceExtractEvent>() {
@Override
public ItemStack @Nullable [] get(FurnaceExtractEvent event) {
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return new ItemStack[]{ItemStack.of(event.getItemType(), event.getItemAmount())};
}
}, EventValues.TIME_NOW);
}
}
101 changes: 101 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtFurnace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.registrations.Classes;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceExtractEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.FurnaceStartSmeltEvent;
import org.jetbrains.annotations.Nullable;

public class EvtFurnace extends SkriptEvent {

static {
Skript.registerEvent("Smelt", EvtFurnace.class, FurnaceSmeltEvent.class,
"[furnace] [ore] smelt[ed|ing] [of %-itemtypes%]",
"[furnace] smelt[ed|ing] of ore")
.description("Called when a furnace smelts an item in its <a href='expressions.html#ExprFurnaceSlot'>ore slot</a>.")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.examples(
"on smelt:",
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
"on smelt of raw iron:",
"\tbroadcast smelted item",
"\tset smelt item to iron block"
)
.since("1.0, INSERT VERSION (specific item)");
Skript.registerEvent("Fuel Burn", EvtFurnace.class, FurnaceBurnEvent.class, "[furnace] fuel burn[ing] [of %-itemtypes%]")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.description("Called when a furnace burns an item from its <a href='expressions.html#ExprFurnaceSlot'>fuel slot</a>.")
.examples(
"on fuel burning:",
"\tbroadcast fuel burned",
"\tif fuel burned is coal:",
"\t\tadd 20 seconds to burn time"
)
.since("1.0, INSERT VERSION (specific item)");
Skript.registerEvent("Furnace Extract", EvtFurnace.class, FurnaceExtractEvent.class, "furnace extract[ion] [of %-itemtypes%]")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.description("Called when a player takes any item out of the furnace.")
.examples(
"on furnace extract:",
"\tif event-items is an iron ingot:",
"\t\tremove event-items from event-player's inventory"
)
.since("INSERT VERSION");
Skript.registerEvent("Start Smelt", EvtFurnace.class, FurnaceStartSmeltEvent.class,
"[furnace] start [of] smelt[ing] [[of] %-itemtypes%]",
"[furnace] smelting start [of %-itemtypes%]")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.description("Called when a furnace starts smelting an item in its ...")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.examples(
"on smelting start:",
"\tif the smelting item is raw iron:",
"\t\tset total cook time to 1 second",
"on smelting start of raw iron:"
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
)
.since("INSERT VERSION");
}

private @Nullable Literal<Object> types;
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
if (exprs[0] != null)
types = (Literal<Object>) exprs[0];
return true;
}

@Override
public boolean check(Event event) {
if (types == null)
return true;

ItemType item;

if (event instanceof FurnaceSmeltEvent smeltEvent) {
item = new ItemType(smeltEvent.getSource());
} else if (event instanceof FurnaceBurnEvent burnEvent) {
item = new ItemType(burnEvent.getFuel());
} else if (event instanceof FurnaceExtractEvent extractEvent) {
item = new ItemType(extractEvent.getItemType());
} else if (event instanceof FurnaceStartSmeltEvent startEvent) {
item = new ItemType(startEvent.getSource());
} else {
assert false;
return false;
}

return types.check(event, o -> {
if (o instanceof ItemType)
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
return ((ItemType) o).isSupertypeOf(item);
return false;
});
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "smelt/burn/extract/start smelt of " + Classes.toString(types);
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
}

}
10 changes: 0 additions & 10 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
import org.bukkit.event.entity.SheepRegrowWoolEvent;
import org.bukkit.event.entity.SlimeSplitEvent;
import org.bukkit.event.entity.PiglinBarterEvent;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
Expand Down Expand Up @@ -222,14 +220,6 @@ public class SimpleEvents {
.description("Called when the hunger bar of a player changes, i.e. either increases by eating or decreases over time.")
.examples("on food bar change:")
.since("1.4.4");
Skript.registerEvent("Fuel Burn", SimpleEvent.class, FurnaceBurnEvent.class, "fuel burn[ing]")
.description("Called when a furnace burns an item from its <a href='expressions.html#ExprFurnaceSlot'>fuel slot</a>.")
.examples("on fuel burning:")
.since("1.0");
Skript.registerEvent("Smelt", SimpleEvent.class, FurnaceSmeltEvent.class, "[ore] smelt[ing]", "smelt[ing] of ore") //TODO SkriptEvent for "smelt[ing] of %itemtype%"
.description("Called when a furnace smelts an item in its <a href='expressions.html#ExprFurnaceSlot'>ore slot</a>.")
.examples("on smelt:")
.since("1.0");
Skript.registerEvent("Leaves Decay", SimpleEvent.class, LeavesDecayEvent.class, "leaves decay[ing]")
.description("Called when a leaf block decays due to not being connected to a tree.")
.examples("on leaves decay:")
Expand Down
170 changes: 0 additions & 170 deletions src/main/java/ch/njol/skript/expressions/ExprBurnCookTime.java

This file was deleted.

12 changes: 5 additions & 7 deletions src/main/java/ch/njol/skript/expressions/ExprFireTicks.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,19 @@ public class ExprFireTicks extends SimplePropertyExpression<Entity, Timespan> {
}

@Override
@Nullable
public Timespan convert(Entity entity) {
return Timespan.fromTicks(Math.max(entity.getFireTicks(), 0));
public @Nullable Timespan convert(Entity entity) {
return new Timespan(Timespan.TimePeriod.TICK, Math.max(entity.getFireTicks(), 0));
}

@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
return (mode != ChangeMode.REMOVE_ALL) ? CollectionUtils.array(Timespan.class) : null;
}

@Override
public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
Entity[] entities = getExpr().getArray(event);
int change = delta == null ? 0 : (int) ((Timespan) delta[0]).getTicks();
int change = delta == null ? 0 : (int) ((Timespan) delta[0]).getAs(Timespan.TimePeriod.TICK);
switch (mode) {
case REMOVE:
change = -change;
Expand All @@ -75,7 +73,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
}

@Override
public Class<? extends Timespan> getReturnType() {
public Class<Timespan> getReturnType() {
return Timespan.class;
}

Expand Down
Loading