Skip to content

Commit

Permalink
Changed argument order of newer methods in DeprecationUtils to allow …
Browse files Browse the repository at this point in the history
…for better conversion from regular methods; fixed build warnings by adding class argument to newer methods; implemented those methods.

Fixed some brewing stand event values
  • Loading branch information
JakeGBLP committed Jan 19, 2025
1 parent fa318b2 commit dce0b83
Show file tree
Hide file tree
Showing 34 changed files with 232 additions and 637 deletions.
9 changes: 9 additions & 0 deletions src/main/java/it/jakegblp/lusk/api/BlockWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.meta.BlockDataMeta;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -302,6 +303,14 @@ public void setBrewingFuel(ItemType ingredient) {
}
}

@Nullable
public BrewerInventory getBrewerInventory() {
if (getBlockState() instanceof BrewingStand brewingStand) {
return brewingStand.getInventory();
}
return null;
}

@Nullable
public Integer getBrewingFuelLevel() {
if (getBlockState() instanceof BrewingStand brewingStand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ public enum ExtendedPropertyType {
BE("(is|are)","(isn't|is not|aren't|are not)"),
CAN("can","(can't|cannot|can not)"),
HAVE("(has|have)","(doesn't|does not|do not|don't) have"),
WILL("will","(will (not|neither)|won't)"),
WOULD("would","(would (not|neither)|wouldn't)"),
COULD("could","(could (not|neither)|couldn't)"),
SHOULD("should","(should (not|neither)|shouldn't)"),;
WILL("will","(will not|won't)"),
WOULD("would","(would not|wouldn't)"),
COULD("could","(could not|couldn't)"),
SHOULD("should","(should not|shouldn't)"),
WAS("(was|were)","(was not|wasn't|were not|weren't)"),;

private final String normal, negated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static it.jakegblp.lusk.utils.DeprecationUtils.test;

@Name("Anvil GUI - is Viewing")
@Description("Checks if a player is currently viewing a specific anvil GUI or any at all.")
@Examples({"if player is viewing any anvil guis:\n\tbroadcast \"%player% is viewing an anvil gui!\""})
@Since("1.3")
public class CondAnvilGuiViewing extends Condition {
static {
static { // todo: property condition?
Skript.registerCondition(CondAnvilGuiViewing.class,
"%players% (is[not:(n't| not)]|are[not:(n't| not)]) viewing (any:an[y] anvil gui[s]|" + Constants.ANVIL_GUI_PREFIX + " %-anvilguiinventory%)");
}
Expand All @@ -34,9 +36,7 @@ public class CondAnvilGuiViewing extends Condition {
@SuppressWarnings("unchecked")
public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @NotNull Kleenean isDelayed, @NotNull SkriptParser.ParseResult parser) {
any = parser.hasTag("any");
if (!any) {
anvilGuiWrapperExpression = (Expression<AnvilGuiWrapper>) expressions[1];
}
if (!any) anvilGuiWrapperExpression = (Expression<AnvilGuiWrapper>) expressions[1];
playerExpression = (Expression<Player>) expressions[0];
setNegated(parser.hasTag("not"));
return true;
Expand All @@ -49,13 +49,11 @@ public boolean init(Expression<?> @NotNull [] expressions, int matchedPattern, @

@Override
public boolean check(@NotNull Event event) {
return playerExpression.check(event, player -> {
return test(playerExpression, event, player -> {
if (any) return AnvilGuiWrapper.isViewingAnyAnvilGui(player);
AnvilGuiWrapper anvilGuiWrapper = anvilGuiWrapperExpression.getSingle(event);
if (anvilGuiWrapper == null) {
return false;
}
if (anvilGuiWrapper == null) return false;
return anvilGuiWrapper.isOpenTo(player);
});
}, Player.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import ch.njol.skript.Skript;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import ch.njol.skript.util.slot.InventorySlot;
import ch.njol.skript.util.slot.Slot;
import it.jakegblp.lusk.api.events.*;
import it.jakegblp.lusk.api.AnvilGuiWrapper;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;

import static it.jakegblp.lusk.utils.Constants.ANVIL_GUI_PREFIX;
import static it.jakegblp.lusk.utils.DeprecationUtils.registerEventValue;

public class EvtAnvilGuiEvents {
static {
Expand All @@ -37,40 +36,15 @@ public class EvtAnvilGuiEvents {
.examples("on anvil gui close:")
.since("1.3");

EventValues.registerEventValue(AnvilGuiClickEvent.class, Integer.class, new Getter<>() {
@Override
public Integer get(final AnvilGuiClickEvent e) {
return e.getSlot();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(AnvilGuiClickEvent.class, Slot.class, new Getter<>() {
@Override
public Slot get(final AnvilGuiClickEvent e) {
return new InventorySlot(e.getInventory(), e.getSlot());
}
}, EventValues.TIME_NOW);
registerEventValue(AnvilGuiClickEvent.class, Integer.class, AnvilGuiClickEvent::getSlot, EventValues.TIME_NOW);
registerEventValue(AnvilGuiClickEvent.class, Slot.class, e -> new InventorySlot(e.getInventory(), e.getSlot()), EventValues.TIME_NOW);

// click and close only
EventValues.registerEventValue(AnvilGuiSnapshotEvent.class, String.class, new Getter<>() {
@Override
public @NotNull String get(final AnvilGuiSnapshotEvent e) {
return e.getText();
}
}, EventValues.TIME_NOW);
registerEventValue(AnvilGuiSnapshotEvent.class, String.class, AnvilGuiSnapshotEvent::getText, EventValues.TIME_NOW);

// common event values
EventValues.registerEventValue(AnvilGuiEvent.class, AnvilGuiWrapper.class, new Getter<>() {
@Override
public @NotNull AnvilGuiWrapper get(final AnvilGuiEvent e) {
return e.getAnvil();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(AnvilGuiEvent.class, Inventory.class, new Getter<>() {
@Override
public @NotNull Inventory get(final AnvilGuiEvent e) {
return e.getInventory();
}
}, EventValues.TIME_NOW);
registerEventValue(AnvilGuiEvent.class, AnvilGuiWrapper.class, AnvilGuiEvent::getAnvil, EventValues.TIME_NOW);
registerEventValue(AnvilGuiEvent.class, Inventory.class, AnvilGuiEvent::getInventory, EventValues.TIME_NOW);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import ch.njol.skript.Skript;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.block.BellResonateEvent;
import org.bukkit.event.block.BellRingEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static it.jakegblp.lusk.utils.Constants.*;
import static it.jakegblp.lusk.utils.DeprecationUtils.registerEventValue;

@SuppressWarnings("unused")
public class EvtBellEvents {
Expand All @@ -24,30 +22,15 @@ public class EvtBellEvents {
A bell will only resonate if raiders are in the vicinity of the bell.""")
.examples("")
.since("1.0.2");
EventValues.registerEventValue(BellResonateEvent.class, LivingEntity[].class, new Getter<>() {
@Override
public LivingEntity @NotNull [] get(BellResonateEvent e) {
return e.getResonatedEntities().toArray(new LivingEntity[0]);
}
}, EventValues.TIME_NOW);
registerEventValue(BellResonateEvent.class, LivingEntity[].class, e -> e.getResonatedEntities().toArray(new LivingEntity[0]), EventValues.TIME_NOW);
}
if (SPIGOT_HAS_BELL_RING_EVENT && !SKRIPT_2_9) {
Skript.registerEvent("Bell - on Ring", SimpleEvent.class, BellRingEvent.class, "bell ring[ing]", "bell rung")
.description("`DEPRECATED SINCE SKRIPT 2.9`\nCalled when a bell is being rung.")
.examples("")
.since("1.0.2, 1.2 (Deprecated)");
EventValues.registerEventValue(BellRingEvent.class, BlockFace.class, new Getter<>() {
@Override
public @NotNull BlockFace get(final BellRingEvent e) {
return e.getDirection();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BellRingEvent.class, Entity.class, new Getter<>() {
@Override
public @Nullable Entity get(final BellRingEvent e) {
return e.getEntity();
}
}, EventValues.TIME_NOW);
registerEventValue(BellRingEvent.class, BlockFace.class, BellRingEvent::getDirection, EventValues.TIME_NOW);
registerEventValue(BellRingEvent.class, Entity.class, BellRingEvent::getEntity, EventValues.TIME_NOW);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import ch.njol.skript.Skript;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import io.papermc.paper.event.block.BlockBreakProgressUpdateEvent;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.event.block.FluidLevelChangeEvent;
import org.jetbrains.annotations.NotNull;

import static ch.njol.skript.paperlib.PaperLib.isPaper;
import static it.jakegblp.lusk.utils.Constants.MINECRAFT_1_20_4;
import static it.jakegblp.lusk.utils.DeprecationUtils.registerEventValue;

public class EvtBlockEvents {
static {
Expand All @@ -20,12 +19,7 @@ public class EvtBlockEvents {
Called when the fluid level of a block changes due to changes in adjacent blocks.""")
.examples("on fluid level change:")
.since("1.0.4");
EventValues.registerEventValue(FluidLevelChangeEvent.class, BlockData.class, new Getter<>() {
@Override
public @NotNull BlockData get(final FluidLevelChangeEvent e) {
return e.getNewData();
}
}, EventValues.TIME_NOW);
registerEventValue(FluidLevelChangeEvent.class, BlockData.class, FluidLevelChangeEvent::getNewData, EventValues.TIME_NOW);
if (MINECRAFT_1_20_4 && isPaper()) {
Skript.registerEvent("Block - on Damage Update", SimpleEvent.class, BlockBreakProgressUpdateEvent.class,
"block damag(ing|e) update", "block break progress update")
Expand All @@ -34,18 +28,8 @@ public class EvtBlockEvents {
`event-number` = the block damage progress, ranges from 0.0 to 1.0, where 0 is no damage and 1.0 is the most damage.""")
.examples("on block damage update:")
.since("1.3");
EventValues.registerEventValue(BlockBreakProgressUpdateEvent.class, Number.class, new Getter<>() {
@Override
public @NotNull Number get(final BlockBreakProgressUpdateEvent e) {
return e.getProgress();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BlockBreakProgressUpdateEvent.class, Entity.class, new Getter<>() {
@Override
public @NotNull Entity get(final BlockBreakProgressUpdateEvent e) {
return e.getEntity();
}
}, EventValues.TIME_NOW);
registerEventValue(BlockBreakProgressUpdateEvent.class, Number.class, BlockBreakProgressUpdateEvent::getProgress, EventValues.TIME_NOW);
registerEventValue(BlockBreakProgressUpdateEvent.class, Entity.class, BlockBreakProgressUpdateEvent::getEntity, EventValues.TIME_NOW);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockIgniteEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static it.jakegblp.lusk.utils.ArrayUtils.haveSameElements;
import static it.jakegblp.lusk.utils.DeprecationUtils.registerEventValue;

public class EvtBlockIgnite extends SkriptEvent {

Expand All @@ -34,18 +33,8 @@ public class EvtBlockIgnite extends SkriptEvent {
.examples("on lusk block ignite due to lava_ignition:","on lusk player block ignition:")
.since("1.3");

EventValues.registerEventValue(BlockIgniteEvent.class, Entity.class, new Getter<>() {
@Override
public @Nullable Entity get(final BlockIgniteEvent e) {
return e.getIgnitingEntity();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BlockIgniteEvent.class, BlockIgniteEvent.IgniteCause.class, new Getter<>() {
@Override
public BlockIgniteEvent.@NotNull IgniteCause get(final BlockIgniteEvent e) {
return e.getCause();
}
}, EventValues.TIME_NOW);
registerEventValue(BlockIgniteEvent.class, Entity.class, BlockIgniteEvent::getIgnitingEntity, EventValues.TIME_NOW);
registerEventValue(BlockIgniteEvent.class, BlockIgniteEvent.IgniteCause.class, BlockIgniteEvent::getCause, EventValues.TIME_NOW);
}

private boolean justPlayer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import org.bukkit.block.BrewingStand;
import it.jakegblp.lusk.api.BlockWrapper;
import org.bukkit.event.block.BrewingStartEvent;
import org.bukkit.event.inventory.BrewEvent;
import org.bukkit.event.inventory.BrewingStandFuelEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static it.jakegblp.lusk.utils.DeprecationUtils.registerEventValue;

public class EvtBrewingStandEvents {
static {
Expand All @@ -22,33 +19,14 @@ public class EvtBrewingStandEvents {
.description(" Called when a brewing stand starts to brew.")
.examples("")
.since("1.0.2");
EventValues.registerEventValue(BrewingStartEvent.class, Inventory.class, new Getter<>() {
@Override
public @NotNull Inventory get(final BrewingStartEvent e) {
return ((InventoryHolder) e.getBlock()).getInventory();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BrewingStartEvent.class, ItemType.class, new Getter<>() {
@Override
public @Nullable ItemType get(final BrewingStartEvent e) {
ItemStack itemStack = ((BrewingStand) e.getBlock()).getInventory().getIngredient();
if (itemStack != null) {
return new ItemType(itemStack);
}
return null;
}
}, EventValues.TIME_NOW);
registerEventValue(BrewingStartEvent.class, Inventory.class, e -> new BlockWrapper(e.getBlock()).getBrewerInventory(), EventValues.TIME_NOW);
registerEventValue(BrewingStartEvent.class, ItemType.class, e -> new BlockWrapper(e.getBlock()).getBrewingIngredient(), EventValues.TIME_NOW);
}
Skript.registerEvent("Brewing Stand - on Brew", SimpleEvent.class, BrewEvent.class, "[brewing stand] brew[ing]")
.description("Called when the brewing of the contents inside a Brewing Stand is complete.")
.examples("")
.since("1.0.2");
EventValues.registerEventValue(BrewEvent.class, Inventory.class, new Getter<>() {
@Override
public @NotNull Inventory get(final BrewEvent e) {
return e.getContents();
}
}, EventValues.TIME_NOW);
registerEventValue(BrewEvent.class, Inventory.class, BrewEvent::getContents, EventValues.TIME_NOW);
Skript.registerEvent("Brewing Stand - on Fuel", SimpleEvent.class, BrewingStandFuelEvent.class, "brewing [stand] fuel [consume]")
.description("Called when an ItemStack is about to increase the fuel level of a brewing stand.")
.examples("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import ch.njol.skript.Skript;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import io.papermc.paper.event.block.BlockFailedDispenseEvent;
import io.papermc.paper.event.block.BlockPreDispenseEvent;
import org.bukkit.entity.Entity;
import org.bukkit.event.block.BlockDispenseArmorEvent;
import org.jetbrains.annotations.NotNull;

import static it.jakegblp.lusk.utils.DeprecationUtils.registerEventValue;

public class EvtDispenserEvents {
static {
Expand All @@ -17,12 +17,7 @@ public class EvtDispenserEvents {
.description("Called when an equipable item is dispensed from a block and equipped on a nearby entity.")
.examples("")
.since("1.0.0");
EventValues.registerEventValue(BlockDispenseArmorEvent.class, Entity.class, new Getter<>() {
@Override
public Entity get(final BlockDispenseArmorEvent e) {
return e.getTargetEntity();
}
}, EventValues.TIME_NOW);
registerEventValue(BlockDispenseArmorEvent.class, Entity.class, BlockDispenseArmorEvent::getTargetEntity, EventValues.TIME_NOW);
}
if (Skript.classExists("io.papermc.paper.event.block.BlockFailedDispenseEvent")) {
Skript.registerEvent("Dispenser - on Dispense Fail", SimpleEvent.class, BlockFailedDispenseEvent.class, "dispense fail", "failed [to] dispense")
Expand All @@ -39,12 +34,7 @@ public Entity get(final BlockDispenseArmorEvent e) {
.examples("")
.requiredPlugins("Paper")
.since("1.0.2");
EventValues.registerEventValue(BlockPreDispenseEvent.class, Integer.class, new Getter<>() {
@Override
public @NotNull Integer get(final BlockPreDispenseEvent e) {
return e.getSlot();
}
}, EventValues.TIME_NOW);
registerEventValue(BlockPreDispenseEvent.class, Integer.class, BlockPreDispenseEvent::getSlot, EventValues.TIME_NOW);
}
}
}
Loading

0 comments on commit dce0b83

Please sign in to comment.