Skip to content

Commit

Permalink
Add item_in_hand and hand fields to block_place event.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lildirt committed Jun 10, 2024
1 parent 002d5bc commit 08f1f57
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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_in_hand: 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_in_hand", 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

0 comments on commit 08f1f57

Please sign in to comment.