本文整理汇总了Java中cn.nukkit.event.player.PlayerItemHeldEvent类的典型用法代码示例。如果您正苦于以下问题:Java PlayerItemHeldEvent类的具体用法?Java PlayerItemHeldEvent怎么用?Java PlayerItemHeldEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlayerItemHeldEvent类属于cn.nukkit.event.player包,在下文中一共展示了PlayerItemHeldEvent类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equipItem
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入依赖的package包/类
/**
* Called when a client equips a hotbar inventorySlot. This method should not be used by plugins.
* This method will call PlayerItemHeldEvent.
*
* @param slot hotbar slot Number of the hotbar slot to equip.
* @return boolean if the equipment change was successful, false if not.
*/
public boolean equipItem(int slot) {
if (!isHotbarSlot(slot)) {
this.sendContents((Player) this.getHolder());
return false;
}
if (this.getHolder() instanceof Player) {
PlayerItemHeldEvent ev = new PlayerItemHeldEvent((Player) this.getHolder(), this.getItem(slot), slot);
this.getHolder().getLevel().getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
this.sendContents(this.getViewers());
return false;
}
}
this.setHeldItemIndex(slot, false);
return true;
}
示例2: chin
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入依赖的package包/类
@EventHandler
public void chin(PlayerItemHeldEvent event){
Player player = event.getPlayer();
Item item =event.getItem();
String iname =item.getCustomName();
Config gunlangjpn =Main.gunlangjpn;
if(gunlangjpn.exists(iname.trim())){
int kindid = gunlangjpn.getInt(iname.trim());
if(cgun.containsKey(player.getName()+"-"+kindid)){
int c = cgun.get(player.getName()+"-"+kindid);
player.sendPopup(lj.usebu_remaining+c);
}
if(kindid >1000){
hgun.put(player.getName(),true);
}else if(hgun.containsKey(player.getName())){
hgun.remove(player.getName());
}
}else{
if(hgun.containsKey(player.getName())){
hgun.remove(player.getName());
}
}
}
示例3: setHeldItemSlot
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入依赖的package包/类
public void setHeldItemSlot(int slot) {
if (slot >= -1 && slot < this.getSize()) {
Item item = this.getItem(slot);
int itemIndex = this.getHeldItemIndex();
if (this.getHolder() instanceof Player) {
PlayerItemHeldEvent ev = new PlayerItemHeldEvent((Player) this.getHolder(), item, slot, itemIndex);
Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
this.sendContents((Player) this.getHolder());
return;
}
}
this.setHotbarSlotIndex(itemIndex, slot);
}
}
示例4: onEquipmentChange
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEquipmentChange(PlayerItemHeldEvent event){
Player player = event.getPlayer();
Item item = event.getItem();
if(this.status == STATUS_ONGOING){
if(item.getId() == GUN_ITEM_ID){
if(containers.containsKey(player.getName())){
containers.get(player.getName()).startShoot();
}
}else{
if(containers.containsKey(player.getName())){
containers.get(player.getName()).stopShoot();
}
}
}
}
示例5: onItemHold
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入依赖的package包/类
@EventHandler
public void onItemHold(PlayerItemHeldEvent event){
if(!this.manager.isAuthenticated(event.getPlayer())){
event.setCancelled();
if(this.getConfig().get("message.send-login", true)){
this.sendLoginMessage(event.getPlayer());
}
}
}
示例6: onPlayerItemHoldEvent
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) {
Player nukkitPlayer = event.getPlayer();
if (nukkitPlayer.isSneaking()) {
return;
}
FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
com.sk89q.worldedit.entity.Player player = fp.getPlayer();
LocalSession session = fp.getSession();
Tool tool = session.getTool(player);
if (tool instanceof ScrollTool) {
final int slot = event.getInventorySlot();
final int oldSlot = event.getSlot();
final int ri;
if ((((slot - oldSlot) <= 4) && ((slot - oldSlot) > 0)) || (((slot - oldSlot) < -4))) {
ri = 1;
} else {
ri = -1;
}
ScrollTool scrollable = (ScrollTool) tool;
if (scrollable.increment(player, ri)) {
final PlayerInventory inv = nukkitPlayer.getInventory();
final Item item = inv.getItem(slot);
final Item newItem = inv.getItem(oldSlot);
inv.setItem(slot, newItem);
inv.setItem(oldSlot, item);
inv.sendContents(nukkitPlayer);
}
}
}