本文整理汇总了Java中org.bukkit.event.inventory.InventoryDragEvent类的典型用法代码示例。如果您正苦于以下问题:Java InventoryDragEvent类的具体用法?Java InventoryDragEvent怎么用?Java InventoryDragEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InventoryDragEvent类属于org.bukkit.event.inventory包,在下文中一共展示了InventoryDragEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equipWeaponEvent
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void equipWeaponEvent(InventoryDragEvent event) {
if (Result.DENY.equals(event.getResult())) return;
HumanEntity human = event.getWhoClicked();
Inventory inv = event.getInventory();
ItemStack prior = event.getOldCursor();
StandardGun priorGun = findGun(prior);
// Don't really care what sort of drag, if we have a gun in inv and this was a gun, deny.
if (priorGun != null && inv != null && !InventoryType.PLAYER.equals(inv.getType()) && priorGun.isLimitToOne() && priorGun.hasGun(human)) {
event.setResult(Result.DENY);
// yes this will prevent drag style of weapon in chest invs. Oh well.
}
}
示例2: equipWeaponEvent
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void equipWeaponEvent(InventoryDragEvent event) {
if (!enabled) return;
HumanEntity human = event.getWhoClicked();
boolean alreadyHasGun = hasGun(human);
Inventory inv = event.getInventory();
ItemStack prior = event.getOldCursor();
// Don't really care what sort of drag, if we have a gun in inv and this was a gun, deny.
if (alreadyHasGun && (inv != null && !InventoryType.PLAYER.equals(inv.getType()))
&& (prior != null && isGun(prior))) {
event.setResult(Result.DENY);
// yes this will prevent drag style of weapon in chest invs. Oh well.
}
}
示例3: onInventoryDrag
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void onInventoryDrag(InventoryDragEvent e) {
Player p = (Player) e.getWhoClicked();
if(!inventories.containsKey(p))
return;
SmartInventory inv = inventories.get(p);
for(int slot : e.getRawSlots()) {
if(slot >= p.getOpenInventory().getTopInventory().getSize())
continue;
e.setCancelled(true);
break;
}
inv.getListeners().stream()
.filter(listener -> listener.getType() == InventoryDragEvent.class)
.forEach(listener -> ((InventoryListener<InventoryDragEvent>) listener).accept(e));
}
示例4: afterEquipChange
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void afterEquipChange(final InventoryDragEvent event) {
final Player player = (Player) event.getWhoClicked();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
new BukkitRunnable() {
@Override
public void run() {
InventoryView inventoryView = event.getView();
for (int slot : event.getRawSlots()) {
ItemStack item = inventoryView.getItem(slot);
if (CustomItem.isCustomItem(item)) {
ItemManager.updateStats((Player) event.getWhoClicked());
}
}
}
}.runTaskLater(RPGInventory.getInstance(), 1);
}
示例5: onInventoryDrag
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onInventoryDrag(InventoryDragEvent event) {
HumanEntity humanEntity = event.getWhoClicked();
if (humanEntity instanceof Player) {
Player player = (Player) humanEntity;
PearlNameFaker pearlNameFaker = itemNameFakes.get(player.getUniqueId());
if (pearlNameFaker == null)
return;
for (Map.Entry<Integer, ItemStack> entry : event.getNewItems().entrySet()) {
if (entry.getKey() == player.getInventory().getHeldItemSlot()) {
pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(player.getItemInHand()), player.getInventory().getHeldItemSlot());
break;
}
}
}
}
示例6: onEvent
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@Override
public void onEvent(InventoryEvent event) {
if (event instanceof InventoryClickEvent) {
InventoryClickEvent clickEvent = ((InventoryClickEvent) event);
if (isTop(event, clickEvent.getRawSlot())) {
notify(event);
}
} else if (event instanceof InventoryDragEvent) {
InventoryDragEvent dragEvent = ((InventoryDragEvent) event);
for (int slot : dragEvent.getRawSlots()) {
if (isTop(event, slot)) {
notify(event);
break;
}
}
}
}
示例7: handle
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@Override
public void handle(GUIEvent<InventoryEvent> event) {
InventoryEvent nativeEvent = event.getEvent();
if (nativeEvent instanceof InventoryClickEvent) {
InventoryClickEvent clickEvent = (InventoryClickEvent) nativeEvent;
if (clickEvent.getRawSlot() < clickEvent.getInventory().getSize())
receive(event);
} else if (nativeEvent instanceof InventoryDragEvent) {
InventoryDragEvent dragEvent = (InventoryDragEvent) nativeEvent;
for (int slot : dragEvent.getRawSlots()) {
if (slot < dragEvent.getInventory().getSize()) {
receive(event);
break;
}
}
}
}
示例8: onInventoryDrag
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
/**
* Handle inventory dragging properly
* @param event
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
Map<Integer, ItemStack> items = event.getNewItems();
for(Integer slot : items.keySet()) {
ItemStack item = items.get(slot);
ExilePearl pearl = pearlApi.getPearlFromItemStack(item);
if(pearl != null) {
boolean clickedTop = event.getView().convertSlot(slot) == slot;
InventoryHolder holder = clickedTop ? event.getView().getTopInventory().getHolder() : event.getView().getBottomInventory().getHolder();
updatePearlHolder(pearl, holder, event);
if(event.isCancelled()) {
return;
}
}
}
}
示例9: onInventoryDrag
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler
public void onInventoryDrag(InventoryDragEvent event) {
if(!event.getInventory().equals(i) || !(event.getWhoClicked() instanceof Player)) return;
Player p = (Player) event.getWhoClicked();
boolean invModified = false;
for(int slot : event.getRawSlots()) {
if(slot < i.getSize()) {
if(invSlots.contains(slot)) {
invModified = true;
} else {
event.setCancelled(true);
return;
}
}
}
if(invModified) {
if(plugin.checkBlockPermission(p, as.getLocation().getBlock())) {
updateInventory();
} else {
event.setCancelled(true);
p.sendMessage(ChatColor.RED + Config.wgNoPerm);
}
}
}
示例10: OnInventoryDragEvent
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOW)
public void OnInventoryDragEvent(InventoryDragEvent event) {
if (event.isCancelled()) {
return;
}
for (int slot : event.getRawSlots()) {
if (slot < event.getView().getTopInventory().getSize()) {
if (guiInventories.containsKey(event.getView().getTopInventory().getName())) {
event.setCancelled(true);
return;
}
}
}
}
示例11: onInventoryDrag
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event)
{
if (event.getWhoClicked() instanceof Player)
{
if (!this.inventoryChanges.containsKey(event.getWhoClicked().getUniqueId()))
{
return;
}
Inventory inventory = event.getInventory();
int amount = 0;
for (Entry<Integer, ItemStack> entry : event.getNewItems().entrySet())
{
if (entry.getKey() < inventory.getSize())
{
amount += entry.getValue().getAmount();
}
}
this.prepareForLogging((Player)event.getWhoClicked(), new ItemData(event.getOldCursor()), amount);
}
}
示例12: onPlayerClickTrinket2
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler
public void onPlayerClickTrinket2(InventoryDragEvent event) {
if (event.getRawSlots().contains(45)) {
event.setCancelled(true);
if (event.getWhoClicked().getGameMode() != GameMode.ADVENTURE && event.getWhoClicked().getGameMode() != GameMode.SURVIVAL) {
event.getWhoClicked().getInventory().setItemInOffHand(null);
}
if (event.getWhoClicked() instanceof Player)
((Player) event.getWhoClicked()).updateInventory();
}
}
示例13: onPlayerDragInventory
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onPlayerDragInventory(InventoryDragEvent event) {
// This is when you spread items evenly across slots by dragging
if(!(event.getWhoClicked() instanceof Player)) {
return;
}
Player player = (Player) event.getWhoClicked();
ItemStack transferred = event.getOldCursor().clone();
transferred.setAmount(0);
Inventory externalInventory = null;
for(Map.Entry<Integer, ItemStack> entry : event.getNewItems().entrySet()) {
Inventory inventory = getLocalInventory(event.getView(), entry.getKey());
if(inventory.getHolder() != player) {
// Add stacks to the total if they are dragged over an external inventory
externalInventory = inventory;
transferred.setAmount(transferred.getAmount() + entry.getValue().getAmount());
}
}
if(externalInventory != null) {
int initialQuantity = transferred.getAmount();
PlayerItemTransferEvent transferEvent = new PlayerItemTransferEvent(
event, ItemTransferEvent.Type.PLACE, player,
Optional.empty(),
Optional.of(new InventorySlot<>(externalInventory)),
transferred, null, initialQuantity,
event.getOldCursor()
);
this.callEvent(transferEvent);
if(initialQuantity != transferEvent.getQuantity()) {
// If the quantity changes, we have to cancel the entire drag,
// because bukkit does not let us modify the dragged stacks.
event.setCancelled(true);
}
}
}
示例14: onInventoryDrag
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onInventoryDrag(InventoryDragEvent event) {
Player player = (Player) event.getWhoClicked();
if (!InventoryManager.playerIsLoaded(player)) {
return;
}
for (Integer rawSlotId : event.getRawSlots()) {
ItemStack cursor = event.getOldCursor();
Inventory inventory = event.getInventory();
if (PetManager.isPetItem(cursor)) {
event.setCancelled(true);
return;
}
if (inventory.getType() == InventoryType.CRAFTING) {
if (InventoryManager.get(player).isOpened()) {
return;
}
// Shield slot is QUICKBAR and has rawId - 45 o.O
if (rawSlotId >= 1 && rawSlotId <= 8 || rawSlotId == 45) {
event.setCancelled(true);
return;
}
} else if (InventoryAPI.isRPGInventory(inventory)) {
if (rawSlotId < 54) {
event.setCancelled(true);
return;
}
}
}
}
示例15: onDragEquip
import org.bukkit.event.inventory.InventoryDragEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onDragEquip(InventoryDragEvent event) {
Player player = (Player) event.getWhoClicked();
if (!InventoryManager.playerIsLoaded(player) || InventoryAPI.isRPGInventory(event.getInventory())) {
return;
}
if (event.getRawSlots().size() == 1) {
int slot = (int) event.getRawSlots().toArray()[0];
event.setCancelled(slot >= 5 && slot <= 8 && event.getInventory().getType() == InventoryType.CRAFTING);
}
}