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

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

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

Inventory.getViewers介绍

[英]Gets a list of players viewing the inventory. Note that a player is considered to be viewing their own inventory and internal crafting screen even when said inventory is not open. They will normally be considered to be viewing their inventory even when they have a different inventory screen open, but it's possible for customized inventory screens to exclude the viewer's inventory, so this should never be assumed to be non-empty.
[中]获取查看资源清册的玩家列表。请注意,玩家被认为是在查看自己的库存和内部工艺屏幕,即使所述库存未打开。即使他们打开了不同的库存屏幕,他们通常也会被视为在查看他们的库存,但定制的库存屏幕可能会排除查看者的库存,因此不应假设这是非空的。

代码示例

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

/**
 * Gets the list of players viewing the primary (upper) inventory involved
 * in this event
 *
 * @return A list of people viewing.
 */
public List<HumanEntity> getViewers() {
  return transaction.getTopInventory().getViewers();
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public List<HumanEntity> getViewers() {
  return base.getViewers();
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public List<HumanEntity> getViewers() {
  return base.getViewers();
}

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

@Override
public List<MCHumanEntity> getViewers() {
  List<MCHumanEntity> retn = new ArrayList<>();
  for(HumanEntity human : i.getViewers()) {
    retn.add(new BukkitMCHumanEntity((human)));
  }
  return retn;
}

代码示例来源:origin: xXKeyleXx/MyPet

@Override
public List<HumanEntity> getViewers() {
  if (minecraftInventory == null) {
    return Collections.emptyList();
  }
  return minecraftInventory.getBukkitInventory().getViewers();
}

代码示例来源:origin: BuycraftPlugin/BuycraftX

public void closeAll() {
  for (HumanEntity entity : ImmutableList.copyOf(inventory.getViewers())) {
    entity.closeInventory();
  }
}

代码示例来源:origin: SpigotMC/Spigot-API

/**
 * Gets the list of players viewing the primary (upper) inventory involved
 * in this event
 *
 * @return A list of people viewing.
 */
public List<HumanEntity> getViewers() {
  return transaction.getTopInventory().getViewers();
}

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

@Override
public void updateViewers() {
  for(HumanEntity human : i.getViewers()) {
    if(human instanceof Player) {
      ((Player) human).updateInventory();
    }
  }
}

代码示例来源:origin: BuycraftPlugin/BuycraftX

public static void replaceInventory(Inventory oldInv, Inventory newInv) {
  // getViewers() is updated as we remove players, so we need to make a copy
  for (HumanEntity entity : ImmutableList.copyOf(oldInv.getViewers())) {
    entity.openInventory(newInv);
  }
}

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

public void close() {
  for(HumanEntity human: new ArrayList<>(toInventory().getViewers())) {
    human.closeInventory();
  }
}

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

public void close() {
  for(HumanEntity human: new ArrayList<>(toInventory().getViewers())) {
    human.closeInventory();
  }
}

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

public static void scheduleUpdate(Inventory inventory) {
    for (HumanEntity humanEntity : inventory.getViewers()) {
      if (humanEntity instanceof Player) {
        new PlayerUpdateInventoryTask((Player) humanEntity).runTask(mcMMO.p);
      }
    }
  }
}

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

public void clearInventory(Location l) {
  BlockMenu menu = getInventory(l);
  for (HumanEntity human: new ArrayList<>(menu.toInventory().getViewers())) {
    human.closeInventory();
  }
  inventories.get(l).delete(l);
  inventories.remove(l);
}

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

@Override
public double[] getShape(final BlockCache blockCache, 
    final World world, final int x, final int y, final int z) {
  final Block block = world.getBlockAt(x, y, z);
  final BlockState state = block.getState();
  //final BlockData blockData = state.getBlockData();
  if (state instanceof Container) {
    if (!((Container) state).getInventory().getViewers().isEmpty()) {
      return new double[] {0.0, 0.0, 0.0, 1.0, 1.5, 1.0};
    }
  }
  return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
}

代码示例来源:origin: drtshock/PlayerVaults

public void saveVault(Player player, Inventory inventory) {
  if (plugin.getInVault().containsKey(player.getUniqueId().toString())) {
    Inventory inv = Bukkit.createInventory(null, 6 * 9);
    inv.setContents(inventory.getContents().clone());
    if (inventory.getViewers().size() == 1) {
      VaultViewInfo info = plugin.getInVault().get(player.getUniqueId().toString());
      vaultManager.saveVault(inv, info.getVaultName(), info.getNumber());
      plugin.getOpenInventories().remove(info.toString());
    }
    plugin.getInVault().remove(player.getUniqueId().toString());
  }
}

代码示例来源:origin: drtshock/PlayerVaults

@Override
public void onDisable() {
  for (Player player : Bukkit.getOnlinePlayers()) {
    if (this.inVault.containsKey(player.getUniqueId().toString())) {
      Inventory inventory = player.getOpenInventory().getTopInventory();
      if (inventory.getViewers().size() == 1) {
        VaultViewInfo info = this.inVault.get(player.getUniqueId().toString());
        VaultManager.getInstance().saveVault(inventory, player.getUniqueId().toString(), info.getNumber());
        this.openInventories.remove(info.toString());
        // try this to make sure that they can't make further edits if the process hangs.
        player.closeInventory();
      }
      this.inVault.remove(player.getUniqueId().toString());
      debug("Closing vault for " + player.getName());
      player.closeInventory();
    }
  }
  if (getConfig().getBoolean("cleanup.enable", false)) {
    saveSignsFile();
  }
}

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

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent e) {
    if (!cm.isAntiChestViewerDupe) {
      return;
    }
    if (e.getBlock() != null && e.getBlock().getState() instanceof InventoryHolder) {
      InventoryHolder inventory = (InventoryHolder) e.getBlock().getState();
      // 如果容器正在使用则不允许被破坏,以防止利用漏洞刷物品
      if (!inventory.getInventory().getViewers().isEmpty()) {
        e.setCancelled(true);
        e.getPlayer().sendMessage(i18n.tr("antiChestViewerDupeMessage"));
      }
    }
  }
}

相关文章