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

New <context.hand> tag for EntityResurrect event. #2617

Merged
merged 5 commits into from
May 17, 2024
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.denizenscript.denizen.events.entity;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -25,6 +28,7 @@ public class EntityResurrectScriptEvent extends BukkitScriptEvent implements Lis
//
// @Context
// <context.entity> returns the EntityTag being resurrected.
// <context.hand> returns a ElementTag of which hand the totem was in during resurrection, if any. Can be either HAND or OFF_HAND. Available only on MC 1.19+.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an, but also no need to specify ElementTag

//
// @Player when the entity being resurrected is a player.
//
Expand Down Expand Up @@ -55,10 +59,17 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("entity")) {
return entity;
}
return super.getContext(name);
return switch (name) {
case "entity" -> entity;
case "hand" -> {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
yield event.getHand() != null ? new ElementTag(event.getHand()) : null;
}
yield null;
}
default -> super.getContext(name);
};

}

@EventHandler
Expand Down