Skip to content

Instantly share code, notes, and snippets.

@TheNewHEROBRINEX
Last active May 17, 2023 23:30
Show Gist options
  • Save TheNewHEROBRINEX/161575fa78077d3b1043cb529fb92bad to your computer and use it in GitHub Desktop.
Save TheNewHEROBRINEX/161575fa78077d3b1043cb529fb92bad to your computer and use it in GitHub Desktop.
<?php
public function onItemPickup(InventoryPickupItemEvent $event) : void{
$inventory = $event->getInventory();
if($inventory instanceof PlayerInventory){
$player = $inventory->getHolder();
if($player instanceof Player){
$murderPlayer = $this->plugin->findMurderPlayer($player);
$itemEntity = $event->getItem();
$itemItem = $itemEntity->getItem();
if($murderPlayer instanceof MurderPlayer){
$event->setCancelled();
if($murderPlayer->isAlive()){
$murderRole = $murderPlayer->getRoleNonNull();
if(match($itemItem->getId()){
ItemIds::EMERALD => $murderRole->onEmeraldPickup(),
ItemIds::WOODEN_SWORD, ItemIds::STONE_SWORD, ItemIds::IRON_SWORD, ItemIds::GOLDEN_SWORD, ItemIds::DIAMOND_SWORD => $murderRole->onSwordPickup($itemItem),
default => false
}){
$pk = new TakeItemActorPacket(); //play sound and despawn as normal
$pk->eid = $player->getId();
$pk->target = $itemEntity->getId();
$this->getPlugin()->getServer()->broadcastPacket($player->getViewers(), $pk);
$itemEntity->flagForDespawn();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment