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

Add event-item and event-slot to Resurrect Event #5683

Merged
merged 7 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
34 changes: 34 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.FireworkExplodeEvent;
import org.bukkit.event.entity.HorseJumpEvent;
Expand Down Expand Up @@ -143,6 +144,7 @@
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.event.world.WorldEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -1562,5 +1564,37 @@ public Location get(LootGenerateEvent event) {
}
}, EventValues.TIME_NOW);
}
// EntityResurrectEvent
EventValues.registerEventValue(EntityResurrectEvent.class, ItemStack.class, new Getter<ItemStack, EntityResurrectEvent>() {
@Override
@Nullable
public ItemStack get(EntityResurrectEvent event) {
EquipmentSlot hand = event.getHand();
EntityEquipment equipment = event.getEntity().getEquipment();
if (equipment == null)
return null;

if (hand == EquipmentSlot.HAND) {
return equipment.getItemInMainHand();
} else if (hand == EquipmentSlot.OFF_HAND) {
return equipment.getItemInOffHand();
}
return null;
}
}, EventValues.TIME_NOW);
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
EventValues.registerEventValue(EntityResurrectEvent.class, Slot.class, new Getter<Slot, EntityResurrectEvent>() {
@Override
@Nullable
public Slot get(EntityResurrectEvent event) {
EquipmentSlot hand = event.getHand();
EntityEquipment equipment = event.getEntity().getEquipment();
if (equipment == null || hand == null)
return null;
return new ch.njol.skript.util.slot.EquipmentSlot(equipment,
(hand == EquipmentSlot.HAND) ? ch.njol.skript.util.slot.EquipmentSlot.EquipSlot.TOOL
: ch.njol.skript.util.slot.EquipmentSlot.EquipSlot.OFF_HAND);
}
}, EventValues.TIME_NOW);

}
}
20 changes: 10 additions & 10 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,16 +470,16 @@ public class SimpleEvents {
.description("Called when a slime splits. Usually this happens when a big slime dies.")
.examples("on slime split:")
.since("2.2-dev26");
if (Skript.classExists("org.bukkit.event.entity.EntityResurrectEvent")) {
Skript.registerEvent("Resurrect Attempt", SimpleEvent.class, EntityResurrectEvent.class, "[entity] resurrect[ion] [attempt]")
.description("Called when an entity dies, always. If they are not holding a totem, this is cancelled - you can, however, uncancel it.")
.examples("on resurrect attempt:",
" entity is player",
" entity has permission \"admin.undying\"",
" uncancel the event")
.since("2.2-dev28");
SkriptEventHandler.listenCancelled.add(EntityResurrectEvent.class); // Listen this even when cancelled
}
Skript.registerEvent("Resurrect Attempt", SimpleEvent.class, EntityResurrectEvent.class, "[entity] resurrect[ion] [attempt]")
.description("Called when an entity dies, always. If they are not holding a totem, this is cancelled - you can, however, uncancel it.")
.examples(
"on resurrect attempt:",
"\tentity is player",
"\tentity has permission \"admin.undying\"",
"\tuncancel the event"
)
.since("2.2-dev28");
SkriptEventHandler.listenCancelled.add(EntityResurrectEvent.class); // Listen this even when cancelled
Skript.registerEvent("Player World Change", SimpleEvent.class, PlayerChangedWorldEvent.class, "[player] world chang(ing|e[d])")
.description("Called when a player enters a world. Does not work with other entities!")
.examples("on player world change:",
Expand Down