本文整理汇总了Java中org.bukkit.event.inventory.CraftItemEvent.isShiftClick方法的典型用法代码示例。如果您正苦于以下问题:Java CraftItemEvent.isShiftClick方法的具体用法?Java CraftItemEvent.isShiftClick怎么用?Java CraftItemEvent.isShiftClick使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.inventory.CraftItemEvent
的用法示例。
在下文中一共展示了CraftItemEvent.isShiftClick方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCraftAmount
import org.bukkit.event.inventory.CraftItemEvent; //导入方法依赖的package包/类
/**
* Get the amount of items the player had just crafted. This method will
* take into consideration shift clicking & the amount of inventory space
* the player has left.
*
* @param CraftItemEvent
* @return int: actual crafted item amount
*/
public static int getCraftAmount(CraftItemEvent e)
{
if (e.isCancelled())
{
return 0;
}
Player p = (Player) e.getWhoClicked();
if (e.isShiftClick())
{
int itemsChecked = 0;
int possibleCreations = 1;
int amountCanBeMade = 0;
for (ItemStack item : e.getInventory().getMatrix())
{
if (item != null && item.getType() != Material.AIR)
{
if (itemsChecked == 0)
{
possibleCreations = item.getAmount();
itemsChecked++;
} else
{
possibleCreations = Math.min(possibleCreations, item.getAmount());
}
}
}
int amountOfItems = e.getRecipe().getResult().getAmount() * possibleCreations;
ItemStack i = e.getRecipe().getResult();
for (int s = 0; s <= 35; s++)
{
ItemStack test = p.getInventory().getItem(s);
if (test == null || test.getType() == Material.AIR)
{
amountCanBeMade += i.getMaxStackSize();
continue;
}
if (test.isSimilar(i))
{
amountCanBeMade += i.getMaxStackSize() - test.getAmount();
}
}
return amountOfItems > amountCanBeMade ? amountCanBeMade : amountOfItems;
} else
{
return e.getRecipe().getResult().getAmount();
}
}
示例2: onPlayerCraftItem
import org.bukkit.event.inventory.CraftItemEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerCraftItem(final CraftItemEvent e)
{
if (!(e.getWhoClicked() instanceof Player) || !(e.getView().getTopInventory() instanceof CraftingInventory))
return;
if (!e.getView().getType().equals(InventoryType.CRAFTING) && !e.getView().getType().equals(InventoryType.WORKBENCH))
return;
JetpackItem currentItem = JetpackItem.getJetpackItem(e.getCurrentItem());
JetpackItem cursorItem = JetpackItem.getJetpackItem(e.getCursor());
boolean needsUpdateInv = false;
if (currentItem != null && !PermissionsHelper.canCraftJetpack(currentItem, (Player) e.getWhoClicked()))
{
((Player) e.getWhoClicked()).sendMessage(AIOPlugin.getInstance().getLocalizationManager().getConfiguration().getString("message-craft-deny"));
e.setCancelled(true);
needsUpdateInv = true;
return;
}
if ((currentItem != null && cursorItem != null) || (currentItem != null && e.isShiftClick()))
{
e.setCancelled(true);
needsUpdateInv = true;
return;
}
if (currentItem != null && (e.getCursor() == null || e.getCursor().getType().equals(Material.AIR)))
{
JetpackItem currentItemCopy = JetpackItem.getJetpackItem(e.getCurrentItem().clone());
if (currentItemCopy != null)
{
currentItemCopy.setCraftTimestamp();
e.setCursor(currentItemCopy.getItem());
CraftingInventory inv = (CraftingInventory) e.getView().getTopInventory();
int maxSlot = (e.getView().getType().equals(InventoryType.CRAFTING) ? 4 : 9);
for (int i = 1; i <= maxSlot; i++)
{
ItemStack is = inv.getItem(i);
if (is != null && !is.getType().equals(Material.AIR))
{
if (is.getAmount() - 1 <= 0)
inv.remove(is);
else
is.setAmount(is.getAmount() - 1);
}
}
needsUpdateInv = true;
}
}
final boolean _needsUpdateInv = needsUpdateInv;
if ((e.getSlotType().equals(SlotType.ARMOR) && e.getRawSlot() == 6 && (!e.getClick().equals(ClickType.MIDDLE))) || currentItem != null)
{
// Run this next Tick because bukkit and some plugins are changing variables after calling that event
this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run()
{
if (_needsUpdateInv)
{
((Player) e.getWhoClicked()).updateInventory();
}
}
});
}
}
示例3: onCraftItem
import org.bukkit.event.inventory.CraftItemEvent; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCraftItem(CraftItemEvent event) {
if (!(event.getWhoClicked() instanceof Player) || event.getAction() == InventoryAction.NOTHING
|| event.getClick() == ClickType.NUMBER_KEY
&& event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD) {
return;
}
Player player = (Player) event.getWhoClicked();
if (!shouldIncreaseBeTakenIntoAccountNoPermissions(player)) {
return;
}
MultipleAchievements category = MultipleAchievements.CRAFTS;
ItemStack item = event.getCurrentItem();
String craftName = item.getType().name().toLowerCase();
if (!player.hasPermission(category.toPermName() + '.' + craftName)) {
return;
}
if (plugin.getPluginConfig().isConfigurationSection(category + "." + craftName + ':' + item.getDurability())) {
craftName += ":" + item.getDurability();
} else if (!plugin.getPluginConfig().isConfigurationSection(category + "." + craftName)) {
return;
}
int eventAmount = event.getCurrentItem().getAmount();
if (event.isShiftClick()) {
int maxAmount = event.getInventory().getMaxStackSize();
ItemStack[] matrix = event.getInventory().getMatrix();
for (ItemStack itemStack : matrix) {
if (itemStack != null && itemStack.getType() != Material.AIR) {
int itemStackAmount = itemStack.getAmount();
if (itemStackAmount < maxAmount && itemStackAmount > 0) {
maxAmount = itemStackAmount;
}
}
}
eventAmount *= maxAmount;
eventAmount = Math.min(eventAmount, getInventoryAvailableSpace(player, event.getCurrentItem()));
if (eventAmount == 0) {
return;
}
}
updateStatisticAndAwardAchievementsIfAvailable(player, category, craftName, eventAmount);
}