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 31 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 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
9f337b1
Merge remote-tracking branch 'upstream/dev/feature' into dev/FurnaceE…
TheAbsolutionism Nov 23, 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 @@ -121,18 +121,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 @@ -1964,5 +1953,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 Player get(FurnaceExtractEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(FurnaceExtractEvent.class, ItemStack[].class, new Getter<ItemStack[], FurnaceExtractEvent>() {
@Override
public ItemStack[] get(FurnaceExtractEvent event) {
return new ItemStack[]{ItemStack.of(event.getItemType(), event.getItemAmount())};
}
}, EventValues.TIME_NOW);
}
}
113 changes: 113 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,113 @@
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'>input slot</a>.")
.examples(
"on smelt:",
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
"\tclear the smelted item",
"on smelt of raw iron:",
"\tbroadcast smelted item",
"\tset the smelted 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 burned fuel is coal:",
"\t\tadd 20 seconds to burn time"
)
.since("1.0, INSERT VERSION (specific item)");

Skript.registerEvent("Furnace Item Extract", EvtFurnace.class, FurnaceExtractEvent.class, "furnace [item] extract[ion] [of %-itemtypes%]")
.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] smelt[ing] start [of %-itemtypes%]")
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
.description("Called when a furnace starts smelting an item in its ore slot.")
.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:",
"\tadd 20 seconds to total cook time"
)
.since("INSERT VERSION");
}

private @Nullable Literal<ItemType> types;

@Override
@SuppressWarnings("unchecked")
public boolean init(Literal<?>[] exprs, int matchedPattern, ParseResult parseResult) {
if (exprs[0] != null)
types = (Literal<ItemType>) 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, itemType -> itemType.isSupertypeOf(item));
}

@Override
public String toString(@Nullable Event event, boolean debug) {
String result = "";
if (event instanceof FurnaceSmeltEvent) {
result = "smelt";
} else if (event instanceof FurnaceBurnEvent) {
result = "burn";
} else if (event instanceof FurnaceExtractEvent) {
result = "extract";
} else if (event instanceof FurnaceStartSmeltEvent) {
result = "start smelt";
}
return result + " of " + Classes.toString(types);
}

}
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