org.bukkit.inventory.Inventory.getHolder()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中org.bukkit.inventory.Inventory.getHolder()方法的一些代码示例,展示了Inventory.getHolder()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Inventory.getHolder()方法的具体详情如下:
包路径:org.bukkit.inventory.Inventory
类名称:Inventory
方法名:getHolder

Inventory.getHolder介绍

[英]Gets the block or entity belonging to the open inventory
[中]获取属于打开的资源清册的块或实体

代码示例

代码示例来源:origin: Bukkit/Bukkit

public InventoryHolder getLeftSide() {
  return inventory.getLeftSide().getHolder();
}

代码示例来源:origin: Bukkit/Bukkit

public InventoryHolder getRightSide() {
  return inventory.getRightSide().getHolder();
}

代码示例来源:origin: EngineHub/WorldEdit

/**
 * Gets the single block inventory for a potentially double chest.
 * Handles people who have an old version of Bukkit.
 * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
 * in a few months (now = March 2012) // note from future dev - lol
 *
 * @param chest The chest to get a single block inventory for
 * @return The chest's inventory
 */
private Inventory getBlockInventory(Chest chest) {
  try {
    return chest.getBlockInventory();
  } catch (Throwable t) {
    if (chest.getInventory() instanceof DoubleChestInventory) {
      DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
      if (inven.getLeftSide().getHolder().equals(chest)) {
        return inven.getLeftSide();
      } else if (inven.getRightSide().getHolder().equals(chest)) {
        return inven.getRightSide();
      } else {
        return inven;
      }
    } else {
      return chest.getInventory();
    }
  }
}

代码示例来源:origin: mcMMO-Dev/mcMMO

private Block processInventoryOpenOrCloseEvent(Inventory inventory) {
  if (!(inventory instanceof FurnaceInventory)) {
    return null;
  }
  Furnace furnace = (Furnace) inventory.getHolder();
  if (furnace == null) {
    return null;
  }
  return furnace.getBlock();
}

代码示例来源:origin: EngineHub/WorldGuard

public Key(InventoryMoveItemEvent event) {
  cause = transform(event.getInitiator().getHolder());
  source = transform(event.getSource().getHolder());
  target = transform(event.getDestination().getHolder());
}

代码示例来源:origin: catageek/ByteCart

/**
 * Get the holder of the ticket
 *
 * @return the holder
 */
InventoryHolder getTicketHolder() {
  return properties.getFile().getContainer().getHolder();
}

代码示例来源:origin: filoghost/ChestCommands

public static void refreshMenu(Player player) {
  InventoryView view = player.getOpenInventory();
  if (view != null) {
    Inventory topInventory = view.getTopInventory();
    if (topInventory.getHolder() instanceof MenuInventoryHolder) {
      MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder();
      
      if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) {
        ((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory);
      }
    }
  }
}

代码示例来源:origin: AddstarMC/Minigames

@EventHandler(ignoreCancelled = true)
private void cartHopperPickup(InventoryPickupItemEvent event){
  if(hasRegenArea() && minigame.hasPlayers() && event.getInventory().getHolder() instanceof HopperMinecart){
    Location loc = ((HopperMinecart)event.getInventory().getHolder()).getLocation();
    if(blockInRegenArea(loc)){
      addEntity((HopperMinecart)event.getInventory().getHolder(), null, false);
    }
  }
}

代码示例来源:origin: jiongjionger/NeverLag

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
  public void onHopper(InventoryMoveItemEvent e) {
    if (cm.isAntiNetherHopper) {
      if (e.getInitiator().getHolder() instanceof Hopper) {
        Hopper hopper = (Hopper) e.getInitiator().getHolder();
        if (hopper.getWorld().getEnvironment() == World.Environment.NETHER) {
          e.setCancelled(true);
        }
      }
    }
  }
}

代码示例来源:origin: ChestShop-authors/ChestShop-3

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
  public static void onItemMove(InventoryMoveItemEvent event) {
    if (event.getSource() == null || event.getDestination().getHolder() instanceof BlockState) {
      return;
    }

    if (!ChestShopSign.isShopBlock(event.getSource().getHolder())) {
      return;
    }

    event.setCancelled(true);
  }
}

代码示例来源:origin: filoghost/ChestCommands

public static void closeAllMenus() {
  for (Player player : VersionUtils.getOnlinePlayers()) {
    if (player.getOpenInventory() != null) {
      if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) {
        player.closeInventory();
      }
    }
  }
}

代码示例来源:origin: ProSavage/SavageFactions

@EventHandler (priority = EventPriority.HIGH)
public void onPlayerInteractGUI(InventoryClickEvent event) {
 if (event.getClickedInventory() == null) {
  return;
 }
 if (event.getClickedInventory().getHolder() instanceof FactionGUI) {
  event.setCancelled(true);
  ((FactionGUI) event.getClickedInventory().getHolder()).onClick(event.getRawSlot(), event.getClick());
 }
}

代码示例来源:origin: catageek/ByteCart

@Override
  protected void infoPlayer(String address) {
    ((Player) this.getInventory().getHolder()).sendMessage(ChatColor.DARK_GREEN+"[Bytecart] " + ChatColor.YELLOW + ByteCart.myPlugin.getConfig().getString("Info.SetReturnAddress") + " " + ChatColor.RED + address);
  }
}

代码示例来源:origin: jiongjionger/NeverLag

public GUIMaker(Inventory inv) {
  if (inv.getType() == InventoryType.CHEST) { // 自定义大小的 Inventory
    this.inv = Bukkit.createInventory(inv.getHolder(), inv.getSize(), inv.getTitle());
  } else { // 自定义类型的 Inventory
    this.inv = Bukkit.createInventory(inv.getHolder(), inv.getType(), inv.getTitle());
  }
  this.inv.setContents(inv.getContents());
}

代码示例来源:origin: SkyWars/SkyWars

private boolean isKitGuiInvolved(InventoryEvent evt) {
  Inventory inventory = evt.getInventory();
  InventoryHolder holder = inventory.getHolder();
  if (holder instanceof Player) {
    if (((Player) holder).getOpenInventory().getTitle().equals(plugin.getKitGui().getKitGuiTitle())) {
      // This ensure that a player is unable to manipulate their own items when a kit GUI is open.
      return true;
    }
  }
  return inventory.getTitle().equals(plugin.getKitGui().getKitGuiTitle());
}

代码示例来源:origin: catageek/ByteCart

/**
 * Send message to player in the chat window
 *
 * @param signAddress the address got by the player
 */
protected void infoPlayer(String signAddress) {
  ((Player) this.getInventory().getHolder()).sendMessage(ChatColor.DARK_GREEN+"[Bytecart] " + ChatColor.YELLOW + ByteCart.myPlugin.getConfig().getString("Info.SetAddress") + " " + ChatColor.RED + signAddress);
  if (this.getVehicle() == null  && ! ByteCart.myPlugin.getConfig().getBoolean("usebooks"))
    ((Player) this.getInventory().getHolder()).sendMessage(ChatColor.DARK_GREEN+"[Bytecart] " + ChatColor.YELLOW + ByteCart.myPlugin.getConfig().getString("Info.SetAddress2") );
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

@EventHandler (ignoreCancelled = true)
  public void onPreBrew(InventoryClickEvent e) {
    Inventory inventory = e.getInventory();
    if (inventory instanceof BrewerInventory && inventory.getHolder() instanceof BrewingStand) {
      if(e.getRawSlot() < inventory.getSize()) e.setCancelled(SlimefunItem.getByItem(e.getCursor()) != null);
    }
  }
}

代码示例来源:origin: catageek/ByteCart

@Override
  public void destroyWanderer(Inventory inv) {
    int id = ((Vehicle) inv.getHolder()).getEntityId();
    Bukkit.getServer().getPluginManager().callEvent(new UpdaterRemoveEvent(id));
    updaterset.getMap().remove(id);
    inv.clear();
  }
}

代码示例来源:origin: EngineHub/WorldGuard

@EventHandler(ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
  InventoryHolder holder = event.getInventory().getHolder();
  if (holder instanceof BlockState) {
    Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), ((BlockState) holder).getBlock()));
  } else if (holder instanceof Entity) {
    if (!(holder instanceof Player)) {
      Events.fireToCancel(event, new UseEntityEvent(event, create(event.getPlayer()), (Entity) holder));
    }
  }
}

代码示例来源:origin: catageek/ByteCart

@Override
public void run() {
  if ((new BC7011(player.getLocation().getBlock(), ((org.bukkit.entity.Vehicle) inventory.getHolder()))).setAddress(address, null, this.istrain)) {
    LogUtil.sendSuccess(player, ByteCart.myPlugin.getConfig().getString("Info.SetAddress") + " " + address);
    LogUtil.sendSuccess(player, ByteCart.myPlugin.getConfig().getString("Info.GetTTL") + AddressFactory.<AddressRouted>getAddress(inventory).getTTL());
  }
  else
    LogUtil.sendError(player, ByteCart.myPlugin.getConfig().getString("Error.SetAddress") );
}

相关文章