本文整理汇总了Java中org.bukkit.event.inventory.InventoryClickEvent.getWhoClicked方法的典型用法代码示例。如果您正苦于以下问题:Java InventoryClickEvent.getWhoClicked方法的具体用法?Java InventoryClickEvent.getWhoClicked怎么用?Java InventoryClickEvent.getWhoClicked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.inventory.InventoryClickEvent
的用法示例。
在下文中一共展示了InventoryClickEvent.getWhoClicked方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInventoryClick1
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClick1(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ItemStack is = event.getCurrentItem();
if ((event.getCurrentItem() != null) && (event.getCurrentItem().getType() != Material.AIR)) {
if (event.getInventory().getName().equals(ChatColor.DARK_GRAY + "Teleport Menu - Page 1")) {
event.setCancelled(true);
for (int i = 0; i < Bukkit.getOnlinePlayers().size(); i++) {
Player targetPlayer = (Player) Bukkit.getOnlinePlayers().toArray()[i];
Location location = player.getLocation();
if ((event.getCurrentItem().getType() == Material.SKULL_ITEM) && (is.hasItemMeta()) && (is.getItemMeta().getDisplayName().equals(ChatColor.YELLOW + "Teleport to " + ChatColor.GREEN + targetPlayer.getName()))) {
player.closeInventory();
player.teleport(targetPlayer);
player.sendMessage(ChatColor.YELLOW + "You've teleported to " + ChatColor.GREEN + targetPlayer.getDisplayName() + ChatColor.YELLOW + "!");
player.playSound(location, Sound.ENTITY_ENDERMEN_TELEPORT, 100, 1);
player.playEffect(location, Effect.ENDER_SIGNAL, 1);
targetPlayer.playEffect(location, Effect.ENDER_SIGNAL, 1);
}
}
}
}
}
示例2: onInventoryClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ItemStack clicked = event.getCurrentItem();
Inventory inventory = event.getInventory();
if (inventory.getName().equals("Faction Management")) {
if (clicked.getType() == Material.SKULL_ITEM) {
if (event.getClick() == ClickType.LEFT) {
Bukkit.dispatchCommand(player, "f promote " + clicked.getItemMeta().getDisplayName());
event.setCancelled(true);
}
if (event.getClick() == ClickType.MIDDLE){
Bukkit.dispatchCommand(player, "f leader " + clicked.getItemMeta().getDisplayName());
event.setCancelled(true);
}
if (event.getClick() == ClickType.RIGHT) {
Bukkit.dispatchCommand(player, "f demote " + clicked.getItemMeta().getDisplayName());
event.setCancelled(true);
}
}
}
}
示例3: onInventoryClick1
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClick1(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ItemStack is = event.getCurrentItem();
if ((event.getCurrentItem() != null) && (event.getCurrentItem().getType() != Material.AIR)) {
if (event.getInventory().getName().equals(ChatColor.DARK_GRAY + "Teleport Menu - Page 1")) {
event.setCancelled(true);
for (int i = 0; i < Bukkit.getOnlinePlayers().size(); i++) {
Player targetPlayer = (Player) Bukkit.getOnlinePlayers().toArray()[i];
Location location = player.getLocation();
if ((event.getCurrentItem().getType() == Material.SKULL_ITEM) && (is.hasItemMeta()) && (is.getItemMeta().getDisplayName().equals(ChatColor.YELLOW + "Teleport to " + ChatColor.GREEN + targetPlayer.getName()))) {
player.closeInventory();
player.teleport(targetPlayer);
player.sendMessage(ChatColor.YELLOW + "You've teleported to " + ChatColor.GREEN + targetPlayer.getDisplayName() + ChatColor.YELLOW + "!");
player.playSound(location, Sound.ENTITY_ENDERMEN_TELEPORT, 100, 1);
player.playEffect(location, Effect.ENDER_SIGNAL, 1);
targetPlayer.playEffect(location, Effect.ENDER_SIGNAL, 1);
}
}
}
}
}
示例4: onClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onClick(InventoryClickEvent event) {
HumanEntity player = event.getWhoClicked();
Inventory inventory = event.getClickedInventory();
if (inventory == null || !gui.getTitle().equals(inventory.getTitle())) {
return;
}
event.setCancelled(true);
PageGUI.playSound(event);
ItemStack button = inventory.getItem(event.getSlot());
if (button == null) {
return;
}
int current = faction.getImportValue(resource);
if (button.equals(BACK)) {
faction.getTradeMenu().open(player);
return;
} else if (button.equals(exportButton)) {
faction.getGroceryList().put(resource, current - 1);
} else if (button.equals(importButton)) {
faction.getGroceryList().put(resource, current + 1);
}
update();
}
示例5: onInventoryClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onInventoryClick(InventoryClickEvent event) {
HumanEntity humanEntity = event.getWhoClicked();
if (humanEntity instanceof Player) {
Player player = (Player) humanEntity;
PearlNameFaker pearlNameFaker = itemNameFakes.get(player.getUniqueId());
if (pearlNameFaker == null)
return;
// Required to prevent ghost items.
int heldSlot = player.getInventory().getHeldItemSlot();
if (event.getSlot() == heldSlot) {
pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(player.getItemInHand()), heldSlot);
} else if (event.getHotbarButton() == heldSlot) {
pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(event.getCurrentItem()), event.getSlot());
new BukkitRunnable() {
@Override
public void run() {
player.updateInventory();
}
}.runTask(plugin);
}
}
}
示例6: onInventoryClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent event) {
final Player player = (Player) event.getWhoClicked();
//noinspection ConstantConditions
if (!InventoryManager.playerIsLoaded(player)
|| event.getInventory().getType() != InventoryType.WORKBENCH
|| isNotNeededHere(player)) {
return;
}
List<CraftExtension> extensions = CraftManager.getExtensions(player);
for (CraftExtension extension : extensions) {
for (int slot : extension.getSlots()) {
if (slot == event.getRawSlot()) {
event.setCancelled(true);
PlayerUtils.updateInventory(player);
return;
}
}
}
}
示例7: onClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onClick(InventoryClickEvent event) {
ItemStack button = event.getCurrentItem();
if (button == null || button.getType() == Material.AIR) {
return;
}
Inventory inventory = event.getInventory();
PageGUI gui = PageGUI.getByInventory(inventory);
if (gui == null) {
return;
}
event.setCancelled(true);
PageGUI.playSound(event);
int index = gui.getPages().indexOf(inventory);
HumanEntity player = event.getWhoClicked();
if (button.equals(NEXT_PAGE)) {
gui.open(player, index + 1);
} else if (button.equals(PREVIOUS_PAGE)) {
gui.open(player, index - 1);
}
}
示例8: onClickGUI
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onClickGUI(InventoryClickEvent e) {
Inventory inv = e.getInventory();
if (inv == null) {
return;
}
if (i18n.tr("title").equals(inv.getTitle())) {
e.setCancelled(true);
}
if (e.getWhoClicked() instanceof Player) {
Player p = (Player) e.getWhoClicked();
int slot = e.getRawSlot();
if (slot < 0 || slot > inv.getSize()) {
return;
}
GUISortPing guiSortPing = GUISortPingHolder.get(p);
if (guiSortPing != null) {
if (slot == 44) {
p.openInventory(guiSortPing.getPreviousPage());
} else if (slot == 53) {
p.openInventory(guiSortPing.getNextPage());
}
}
}
}
示例9: onClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onClick(InventoryClickEvent event) {
HumanEntity player = event.getWhoClicked();
Inventory inventory = event.getClickedInventory();
if (inventory == null || !gui.getTitle().equals(inventory.getTitle())) {
return;
}
event.setCancelled(true);
PageGUI.playSound(event);
ItemStack button = event.getCurrentItem();
if (INCOME_MANAGEMENT.equals(button)) {
faction.getTradeMenu().open(player);
} else if (TRADE_OFFER.equals(button)) {
plugin.getCommandCache().tradeOffer.onExecute(new String[]{"tradeOffer", faction.getName()}, player);
} else if (STORAGE.equals(button)) {
plugin.getCommandCache().storage.onExecute(new String[]{"storage", faction.getName()}, player);
}
}
示例10: onInventoryClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player p = (Player) event.getWhoClicked();
Inventory inv = event.getInventory();
if (Chat.stripColor(inv.getTitle()).equalsIgnoreCase("Voting Panel")) {
event.setCancelled(true);
if (event.getRawSlot() > 9 || event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR)
return;
ItemStack i = event.getCurrentItem();
Map m = Map.getByTitle(Chat.stripColor(i.getItemMeta().getDisplayName()));
if (m != null) {
m.addVote(p);
p.closeInventory();
event.setCancelled(true);
}
}
}
示例11: __handleInvClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public final void __handleInvClick(InventoryClickEvent e) {
Inventory clickedInventory = e.getClickedInventory();
ClickType clickType = e.getClick();
Player player = (Player) e.getWhoClicked();
ItemStack clicked = e.getCurrentItem();
if (clickedInventory == null)
return;
if (clickedInventory == inventory) {
e.setCancelled(true);
if (clicked != null) {
BiConsumer<Player, ClickType> b;
if ((b = clicks.get(e.getRawSlot())) != null) {
b.accept(player, clickType);
if (updateOnClick && ! destroyed)
update();
}
}
}
}
示例12: onInventoryClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onInventoryClick(InventoryClickEvent ev)
{
if (!(ev.getWhoClicked() instanceof Player) || ev.getCurrentItem() == null)
{
ev.setCancelled(true);
return ;
}
if (ev.getInventory().getName().equals(TeamSelectorGui.INV_NAME))
TeamSelectorGui.onClick((Player)ev.getWhoClicked(), ev.getCurrentItem());
else if (ev.getInventory().getName().equals(MenuGui.INV_NAME))
MenuGui.onClick((Player)ev.getWhoClicked(), ev.getCurrentItem());
ev.setCancelled(true);
}
示例13: onClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler
public void onClick(InventoryClickEvent event) {
if (event.getInventory().getName().equals(this.inventory.getName())) {
event.setCancelled(true);
Player player = (Player) event.getWhoClicked();
if (actions.containsKey(event.getSlot())) {
actions.get(event.getSlot()).run(player);
}
}
}
示例14: onInventoryClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
/**
* Limits the player to one workbench in their inventory at a time, by means of taking the item from another
* inventory.
*
* @param event The event
*/
@EventHandler(ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (event.getCurrentItem().getType().equals(Material.WORKBENCH)
&& player.getInventory().contains(Material.WORKBENCH)) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "You may not take another workbench!");
}
}
示例15: onClick
import org.bukkit.event.inventory.InventoryClickEvent; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
if (!(e.getWhoClicked() instanceof Player))
return;
Player p = (Player) e.getWhoClicked();
if (e.getClickedInventory() == null) return;
if (Objects.equals(e.getClickedInventory().getTitle(), title)) e.setCancelled(true);
if (!USERS.containsKey(p.getUniqueId()))
return;
SimpleMovingInventory inv = USERS.get(p.getUniqueId());
if (e.getCurrentItem() == null)
return;
if (e.getCurrentItem().getItemMeta() == null)
return;
if (e.getCurrentItem().getItemMeta().getDisplayName() == null)
return;
if (sameName(e.getCurrentItem(), nextPage)) {
e.setCancelled(true);
if (inv.currpage < PAGES.size() - 1) {
inv.currpage += 1;
p.openInventory(PAGES.get(inv.currpage));
}
} else if (sameName(e.getCurrentItem(), previousPage)) {
e.setCancelled(true);
if (inv.currpage > 0) {
inv.currpage -= 1;
p.openInventory(PAGES.get(inv.currpage));
}
}
}