本文整理汇总了Java中cn.nukkit.event.inventory.InventoryPickupItemEvent类的典型用法代码示例。如果您正苦于以下问题:Java InventoryPickupItemEvent类的具体用法?Java InventoryPickupItemEvent怎么用?Java InventoryPickupItemEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InventoryPickupItemEvent类属于cn.nukkit.event.inventory包,在下文中一共展示了InventoryPickupItemEvent类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCollideWithPlayer
import cn.nukkit.event.inventory.InventoryPickupItemEvent; //导入依赖的package包/类
@Override
public void onCollideWithPlayer(Player player) {
if(this.getPickupDelay() > 0) {
return;
}
Item item = this.getItem();
PlayerInventory playerInventory = player.getInventory();
if(!(item instanceof Item) || (player.isSurvival() && !playerInventory.canAddItem(item))) {
return;
}
InventoryPickupItemEvent ev;
this.server.getPluginManager().callEvent(ev = new InventoryPickupItemEvent(playerInventory, this));
if(ev.isCancelled()) {
return;
}
TakeItemEntityPacket pk = new TakeItemEntityPacket();
pk.entityRuntimeId = player.getId();
pk.target = this.getId();
Server.broadcastPacket(this.getViewers().values(), pk);
playerInventory.addItem(item);
this.kill();
}
示例2: onItemPickup
import cn.nukkit.event.inventory.InventoryPickupItemEvent; //导入依赖的package包/类
@EventHandler (ignoreCancelled = true)
public void onItemPickup(InventoryPickupItemEvent event){
if(event.getInventory().getHolder() instanceof Player){
Player player = (Player) event.getInventory().getHolder();
EntityItem item = event.getItem();
long now = System.currentTimeMillis();
Long[] lastPickup = this.manager.getLastPickup(player);
if(lastPickup == null || (lastPickup[1] == item.getId() && now - lastPickup[0] > 2000) || lastPickup[1] != item.getId()){
Land land;
if((land = this.provider.findLand(item)) != null && !land.getOption("pickup", false)){
if(!(land.hasPermission(player) || player.hasPermission("economyland.admin.pickup"))){
event.setCancelled(true);
if(lastPickup != null && now - lastPickup[0] > 2000){
player.sendMessage(this.getMessage("pickup-forbidden", new Object[]{
land.getId(), land.getOwner()
}));
}
this.manager.setLastPickup(player, item);
}
}
}else{
event.setCancelled(true);
}
}
}
示例3: onPickup
import cn.nukkit.event.inventory.InventoryPickupItemEvent; //导入依赖的package包/类
@EventHandler
public void onPickup(InventoryPickupItemEvent event){
InventoryHolder holder = event.getInventory().getHolder();
if(holder instanceof Player){
Player player = (Player)holder;
if(this.status == STATUS_ONGOING){
if(containers.containsKey(player.getName())){
containers.get(player.getName()).getGun().addAmmo(30);
}
}
}
event.getItem().kill();
event.setCancelled();
}
示例4: onPickup
import cn.nukkit.event.inventory.InventoryPickupItemEvent; //导入依赖的package包/类
@EventHandler
public void onPickup(InventoryPickupItemEvent event){
InventoryHolder holder = event.getInventory().getHolder();
if(holder instanceof Player){
Player player = (Player)holder;
if(!this.manager.isAuthenticated(player)){
event.setCancelled();
}
}
}
示例5: onInventoryPickupItem
import cn.nukkit.event.inventory.InventoryPickupItemEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryPickupItem(InventoryPickupItemEvent event){
if(event.getItem() instanceof EntityOwnedItem && event.getInventory().getHolder() instanceof Player && !((EntityOwnedItem) event.getItem()).canPickUp((Player) event.getInventory().getHolder())){
event.setCancelled();
}
}