Skip to content

Commit

Permalink
Skript 2.10 prep
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee committed Dec 30, 2024
1 parent 10e8f52 commit 26ba3f3
Show file tree
Hide file tree
Showing 14 changed files with 361 additions and 298 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/shanebeestudios/skbee/api/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Util {

// Shortcut for finding stuff to remove later
public static final boolean IS_RUNNING_SKRIPT_2_9 = Skript.getVersion().isLargerThan(new Version(2, 8, 999));
public static final boolean IS_RUNNING_SKRIPT_2_10 = Skript.getVersion().isLargerThan(new Version(2, 9, 999));
public static final boolean IS_RUNNING_MC_1_21 = Skript.isRunningMinecraft(1, 21);

@SuppressWarnings("deprecation") // Paper deprecation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import com.shanebeestudios.skbee.api.util.Util;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FishHook;
import org.jetbrains.annotations.NotNull;

@Name("Fish Hook - In Open Water")
@Description({"Check if the fish hook is in open water.",
"Open water is defined by a 5x4x5 area of water, air and lily pads.",
"If in open water, treasure items may be caught."})
"Open water is defined by a 5x4x5 area of water, air and lily pads.",
"If in open water, treasure items may be caught.",
"Removed if running Skript 2.10+ (now included in Skript)."})
@Examples("if fish hook is in open water:")
@Since("2.8.0")
public class CondFishHookInOpenWater extends PropertyCondition<Entity> {

static {
register(CondFishHookInOpenWater.class, "in open water", "entities");
if (!Util.IS_RUNNING_SKRIPT_2_10) {
register(CondFishHookInOpenWater.class, "in open water", "entities");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import com.shanebeestudios.skbee.api.util.Util;
import org.bukkit.entity.Entity;
import org.jetbrains.annotations.NotNull;

@Name("Entity - Is Ticking")
@Description("Check if an entity is currently ticking. If they're in a chunk that is not ticking, this will be false.")
@Description({"Check if an entity is currently ticking.",
"If they're in a chunk that is not ticking, this will be false.",
"Removed if running Skript 2.10+ (now included in Skript)."})
@Examples("loop all entities where [input is ticking]:")
@Since("2.6.0")
public class CondEntityTicking extends PropertyCondition<Entity> {

private static final boolean TICKING_METHOD_EXISTS = Skript.methodExists(Entity.class, "isTicking");

static {
register(CondEntityTicking.class, "ticking", "entities");
if (!Util.IS_RUNNING_SKRIPT_2_10) {
register(CondEntityTicking.class, "ticking", "entities");
}
}

@SuppressWarnings("NullableProblems")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,41 +146,43 @@ public Player get(PrepareAnvilEvent event) {
.since("1.8.0");

// Entity Breed Event
Skript.registerEvent("Entity Breed", OtherEvents.class, EntityBreedEvent.class,
"entity breed")
.description("Called when one Entity breeds with another Entity.")
.examples("on entity breed:", "\nif breeding mother is a sheep:",
"\n\nkill breeding player")
.since("1.17.0");

EventValues.registerEventValue(EntityBreedEvent.class, Player.class, new Getter<>() {
@Override
public @Nullable Player get(EntityBreedEvent breedEvent) {
LivingEntity breeder = breedEvent.getBreeder();
if (breeder instanceof Player player) {
return player;
if (!Util.IS_RUNNING_SKRIPT_2_10) {
Skript.registerEvent("Entity Breed", OtherEvents.class, EntityBreedEvent.class,
"entity breed")
.description("Called when one Entity breeds with another Entity.")
.examples("on entity breed:", "\nif breeding mother is a sheep:",
"\n\nkill breeding player")
.since("1.17.0");

EventValues.registerEventValue(EntityBreedEvent.class, Player.class, new Getter<>() {
@Override
public @Nullable Player get(EntityBreedEvent breedEvent) {
LivingEntity breeder = breedEvent.getBreeder();
if (breeder instanceof Player player) {
return player;
}
return null;
}
return null;
}
}, EventValues.TIME_NOW);
}, EventValues.TIME_NOW);

EventValues.registerEventValue(EntityBreedEvent.class, Entity.class, new Getter<>() {
@Override
public Entity get(EntityBreedEvent breedEvent) {
return breedEvent.getEntity();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(EntityBreedEvent.class, Entity.class, new Getter<>() {
@Override
public Entity get(EntityBreedEvent breedEvent) {
return breedEvent.getEntity();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(EntityBreedEvent.class, ItemType.class, new Getter<>() {
@Override
public @Nullable ItemType get(EntityBreedEvent breedEvent) {
ItemStack bredWith = breedEvent.getBredWith();
if (bredWith != null) {
return new ItemType(bredWith);
EventValues.registerEventValue(EntityBreedEvent.class, ItemType.class, new Getter<>() {
@Override
public @Nullable ItemType get(EntityBreedEvent breedEvent) {
ItemStack bredWith = breedEvent.getBredWith();
if (bredWith != null) {
return new ItemType(bredWith);
}
return null;
}
return null;
}
}, EventValues.TIME_NOW);
}, EventValues.TIME_NOW);
}

// Entity Change Block Event
Skript.registerEvent("Entity Change Block", OtherEvents.class, EntityChangeBlockEvent.class,
Expand All @@ -204,49 +206,51 @@ public Entity get(EntityBreedEvent breedEvent) {
}, EventValues.TIME_NOW);

// Block Drop Item Event
Skript.registerEvent("Block Drop Item", OtherEvents.class, BlockDropItemEvent.class,
"block drop item")
.description("This event is called if a block broken by a player drops an item.",
"`event-player` = Player who broke the block.",
"`event-entities` = Item entities which were dropped (may include drops of attached blocks, like a torch).",
"`past event-block` = The block that was broken (This event is called after the block actually breaks).",
"`event-block` = Current state of block after broken (Probably will just be air).")
.examples("on block drop item:",
"\tif past event-block is any ore:",
"\t\tteleport event-entities to player",
"\t\tset {_data} to blockdata of past event-block",
"\t\tset event-block to bedrock",
"\t\twait 2 seconds",
"\t\tset event-block to {_data}")
.since("2.6.0");

EventValues.registerEventValue(BlockDropItemEvent.class, Player.class, new Getter<>() {
@Override
public Player get(BlockDropItemEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);
if (!Util.IS_RUNNING_SKRIPT_2_10) {
Skript.registerEvent("Block Drop Item", OtherEvents.class, BlockDropItemEvent.class,
"block drop item")
.description("This event is called if a block broken by a player drops an item.",
"`event-player` = Player who broke the block.",
"`event-entities` = Item entities which were dropped (may include drops of attached blocks, like a torch).",
"`past event-block` = The block that was broken (This event is called after the block actually breaks).",
"`event-block` = Current state of block after broken (Probably will just be air).")
.examples("on block drop item:",
"\tif past event-block is any ore:",
"\t\tteleport event-entities to player",
"\t\tset {_data} to blockdata of past event-block",
"\t\tset event-block to bedrock",
"\t\twait 2 seconds",
"\t\tset event-block to {_data}")
.since("2.6.0");

EventValues.registerEventValue(BlockDropItemEvent.class, Player.class, new Getter<>() {
@Override
public Player get(BlockDropItemEvent event) {
return event.getPlayer();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(BlockDropItemEvent.class, Block.class, new Getter<>() {
@Override
public Block get(BlockDropItemEvent event) {
return event.getBlock();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BlockDropItemEvent.class, Block.class, new Getter<>() {
@Override
public Block get(BlockDropItemEvent event) {
return event.getBlock();
}
}, EventValues.TIME_NOW);

EventValues.registerEventValue(BlockDropItemEvent.class, Block.class, new Getter<>() {
@Override
public Block get(BlockDropItemEvent event) {
return new BlockStateBlock(event.getBlockState());
}
}, EventValues.TIME_PAST);
EventValues.registerEventValue(BlockDropItemEvent.class, Block.class, new Getter<>() {
@Override
public Block get(BlockDropItemEvent event) {
return new BlockStateBlock(event.getBlockState());
}
}, EventValues.TIME_PAST);

EventValues.registerEventValue(BlockDropItemEvent.class, Item[].class, new Getter<>() {
@Override
public Item @Nullable [] get(BlockDropItemEvent event) {
return event.getItems().toArray(new Item[0]);
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(BlockDropItemEvent.class, Item[].class, new Getter<>() {
@Override
public Item @Nullable [] get(BlockDropItemEvent event) {
return event.getItems().toArray(new Item[0]);
}
}, EventValues.TIME_NOW);
}

// Block Damage Abort Event
if (Skript.classExists("org.bukkit.event.block.BlockDamageAbortEvent")) {
Expand Down
Loading

0 comments on commit 26ba3f3

Please sign in to comment.