本文整理汇总了Java中org.bukkit.event.player.PlayerItemHeldEvent.getNewSlot方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerItemHeldEvent.getNewSlot方法的具体用法?Java PlayerItemHeldEvent.getNewSlot怎么用?Java PlayerItemHeldEvent.getNewSlot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.player.PlayerItemHeldEvent
的用法示例。
在下文中一共展示了PlayerItemHeldEvent.getNewSlot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onQuickSlotHeld
import org.bukkit.event.player.PlayerItemHeldEvent; //导入方法依赖的package包/类
@EventHandler
public void onQuickSlotHeld(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
int slotId = event.getNewSlot();
Slot slot = InventoryManager.getQuickSlot(slotId);
if (slot != null && slot.isCup(player.getInventory().getItem(slotId))) {
event.setCancelled(true);
InventoryUtils.heldFreeSlot(player, slotId,
(event.getPreviousSlot() + 1) % 9 == slotId ? InventoryUtils.SearchType.NEXT : InventoryUtils.SearchType.PREV);
}
}
示例2: onItemHeld
import org.bukkit.event.player.PlayerItemHeldEvent; //导入方法依赖的package包/类
@Override
public void onItemHeld(PlayerItemHeldEvent event) {
int delta = event.getNewSlot() - event.getPreviousSlot();
if (delta == 0) {
return;
} else if (delta >= 6) {
delta -= 9;
} else if (delta <= -6) {
delta += 9;
}
delta = (delta > 0) ? 1 : -1;
int o = getMode().ordinal() + delta;
if (o < 0) {
o = Mode.values().length - 1;
} else if (o >= Mode.values().length) {
o = 0;
}
setMode(Mode.values()[o]);
event.getPlayer().setItemInHand(toItemStack());
}
示例3: onHeld
import org.bukkit.event.player.PlayerItemHeldEvent; //导入方法依赖的package包/类
@EventHandler
public void onHeld(PlayerItemHeldEvent e) {
if (e.isCancelled()) {
return;
}
if (!Utils.isInArena(e.getPlayer())) {
return;
}
if (e.getNewSlot() == 0) {
return;
}
if (e.getNewSlot() >= 2 && e.getNewSlot() <= 4) {
int slot = e.getNewSlot();
Player p = e.getPlayer();
PlayerInventory inv = p.getInventory();
ItemStack item = inv.getItem(slot).clone();
item.setAmount(1);
if (SkillManager.getInstance().isSkillSelector(item)) {
Skill skill = SkillManager.getInstance().getSkillBySelector(item);
if(skill.getSkillType().equals(SkillType.ITEM)){
inv.setItem(0, skill.getShow());
}
else{
Class<?> skillClazz=skill.getClass();
try {
Method method =skillClazz.getMethod("doUpgrade",Player.class);
if(method!=null){
method.invoke(SkillManager.getInstance().getSkillByName(skill.getName()),p);
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
inv.setItem(2, ItemManager.getForbidden(3));
inv.setItem(3, ItemManager.getForbidden(4));
inv.setItem(4, ItemManager.getForbidden(5));
}
}
e.setCancelled(true);
}
示例4: onPlayerItemHoldEvent
import org.bukkit.event.player.PlayerItemHeldEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) {
final Player bukkitPlayer = event.getPlayer();
if (bukkitPlayer.isSneaking()) {
return;
}
FawePlayer<Object> fp = FawePlayer.wrap(bukkitPlayer);
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.getNewSlot();
final int oldSlot = event.getPreviousSlot();
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)) {
if (Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES) {
bukkitPlayer.getInventory().setHeldItemSlot(oldSlot);
} else {
final PlayerInventory inv = bukkitPlayer.getInventory();
final ItemStack item = inv.getItem(slot);
final ItemStack newItem = inv.getItem(oldSlot);
inv.setItem(slot, newItem);
inv.setItem(oldSlot, item);
bukkitPlayer.updateInventory();
}
}
}
}