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 item_in_hand and hand fields to block_place event. #1382

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -16,6 +16,7 @@
import com.laytonsmith.abstraction.bukkit.blocks.BukkitMCBlockState;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCPlayer;
import com.laytonsmith.abstraction.enums.MCEquipmentSlot;
import com.laytonsmith.abstraction.enums.MCIgniteCause;
import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.enums.MCVersion;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.bukkit.event.block.NotePlayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -238,6 +240,14 @@ public MCItemStack getItemInHand() {
return new BukkitMCItemStack(event.getItemInHand());
}

@Override
public MCEquipmentSlot getHand() {
if(event.getHand() == EquipmentSlot.HAND) {
return MCEquipmentSlot.WEAPON;
}
return MCEquipmentSlot.OFF_HAND;
}

@Override
public boolean canBuild() {
return event.canBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCBlockState;
import com.laytonsmith.abstraction.enums.MCEquipmentSlot;
import com.laytonsmith.core.events.BindableEvent;

public interface MCBlockPlaceEvent extends BindableEvent {
Expand All @@ -18,5 +19,7 @@ public interface MCBlockPlaceEvent extends BindableEvent {

MCItemStack getItemInHand();

MCEquipmentSlot getHand();

boolean canBuild();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.enums.MCEquipmentSlot;
import com.laytonsmith.abstraction.enums.MCIgniteCause;
import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.events.MCBlockBreakEvent;
Expand Down Expand Up @@ -326,7 +327,9 @@ public String docs() {
+ "{player: The player's name | block: the block type that was placed"
+ " | against: a block array of the block being placed against"
+ " | oldblock: the old block type that was replaced"
+ " | location: A locationArray for this block} "
+ " | location: A locationArray for this block "
+ " | item: the item used to the place the block "
+ " | hand: hand used to place the block} "
+ "{block} "
+ "{}";
}
Expand Down Expand Up @@ -411,6 +414,12 @@ public Map<String, Mixed> evaluate(BindableEvent e) throws EventException {
map.put("player", new CString(event.getPlayer().getName(), t));
map.put("block", new CString(mat.getName(), t));
map.put("location", ObjectGenerator.GetGenerator().location(block.getLocation(), false));
map.put("item", ObjectGenerator.GetGenerator().item(event.getItemInHand(), Target.UNKNOWN));
if(event.getHand() == MCEquipmentSlot.WEAPON) {
map.put("hand", new CString("main_hand", Target.UNKNOWN));
} else {
map.put("hand", new CString("off_hand", Target.UNKNOWN));
}

MCBlock agstblock = event.getBlockAgainst();
MCMaterial agstmat = agstblock.getType();
Expand Down
Loading