本文整理汇总了Java中org.bukkit.entity.Player.setItemOnCursor方法的典型用法代码示例。如果您正苦于以下问题:Java Player.setItemOnCursor方法的具体用法?Java Player.setItemOnCursor怎么用?Java Player.setItemOnCursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.setItemOnCursor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reset
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void reset(Player player, boolean heal) {
if (heal) player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
player.setFoodLevel(20);
player.setSaturation(20);
player.getInventory().clear();
player.getInventory().setArmorContents(new ItemStack[]{new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR), new ItemStack(Material.AIR)});
player.setItemOnCursor(new ItemStack(Material.AIR));
player.getActivePotionEffects().forEach(potionEffect -> {
try {
player.removePotionEffect(potionEffect.getType());
} catch (NullPointerException ignored) {}
});
player.setFireTicks(0);
player.setFallDistance(0);
player.setTotalExperience(0);
player.setExp(0);
player.setLevel(0);
player.setWalkSpeed(0.2F);
player.setFlySpeed(0.1F);
player.setSneaking(false);
player.setInvulnerable(false);
player.setCanPickupItems(true);
player.setCollidable(true);
player.setFlying(false);
player.setAllowFlight(false);
player.resetTitle();
for (Attribute attribute : Attribute.values()) {
if (player.getAttribute(attribute) == null) continue;
for (AttributeModifier modifier : player.getAttribute(attribute).getModifiers()) {
player.getAttribute(attribute).removeModifier(modifier);
}
}
player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).addModifier(new AttributeModifier(UUID.randomUUID(), "generic.attackSpeed", 24.000D, AttributeModifier.Operation.ADD_SCALAR));
player.updateInventory();
}
示例2: updateInventory
import org.bukkit.entity.Player; //导入方法依赖的package包/类
private static void updateInventory(
@NotNull Player player,
@NotNull Inventory inventory,
int slot,
InventoryType.SlotType slotType,
InventoryAction action,
ItemStack currentItem,
ItemStack cursorItem
) {
if (ActionType.getTypeOfAction(action) == ActionType.DROP) {
return;
}
if (action == InventoryAction.PLACE_ALL) {
if (ItemUtils.isEmpty(currentItem)) {
currentItem = cursorItem.clone();
} else {
currentItem.setAmount(currentItem.getAmount() + cursorItem.getAmount());
}
cursorItem = null;
} else if (action == InventoryAction.PLACE_ONE) {
if (ItemUtils.isEmpty(currentItem)) {
currentItem = cursorItem.clone();
currentItem.setAmount(1);
cursorItem.setAmount(cursorItem.getAmount() - 1);
} else if (currentItem.getMaxStackSize() < currentItem.getAmount() + 1) {
currentItem.setAmount(currentItem.getAmount() + 1);
cursorItem.setAmount(cursorItem.getAmount() - 1);
}
} else if (action == InventoryAction.PLACE_SOME) {
cursorItem.setAmount(currentItem.getMaxStackSize() - currentItem.getAmount());
currentItem.setAmount(currentItem.getMaxStackSize());
} else if (action == InventoryAction.SWAP_WITH_CURSOR) {
ItemStack tempItem = cursorItem.clone();
cursorItem = currentItem.clone();
currentItem = tempItem;
} else if (action == InventoryAction.PICKUP_ALL) {
cursorItem = currentItem.clone();
currentItem = null;
} else if (action == InventoryAction.PICKUP_HALF) {
ItemStack item = currentItem.clone();
if (currentItem.getAmount() % 2 == 0) {
item.setAmount(item.getAmount() / 2);
currentItem = item.clone();
cursorItem = item.clone();
} else {
currentItem = item.clone();
currentItem.setAmount(item.getAmount() / 2);
cursorItem = item.clone();
cursorItem.setAmount(item.getAmount() / 2 + 1);
}
} else if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
player.getInventory().addItem(currentItem);
currentItem = null;
}
if (slotType == InventoryType.SlotType.QUICKBAR) {
if (slot < 9) { // Exclude shield
player.getInventory().setItem(slot, currentItem);
}
} else {
inventory.setItem(slot, currentItem);
}
player.setItemOnCursor(cursorItem);
player.updateInventory();
}
示例3: onArmorSlotClick
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* It happens when player click on armor slot
*/
private void onArmorSlotClick(InventoryClickEvent event, PlayerWrapper playerWrapper, final Slot slot,
ItemStack cursor, ItemStack currentItem) {
final Player player = playerWrapper.getPlayer().getPlayer();
final Inventory inventory = event.getInventory();
final int rawSlot = event.getRawSlot();
InventoryAction action = event.getAction();
ActionType actionType = ActionType.getTypeOfAction(action);
if (InventoryManager.validateArmor(player, action, slot, cursor) && playerWrapper.getInventoryView() != null) {
// Event of equip armor
InventoryClickEvent fakeEvent = new InventoryClickEvent(playerWrapper.getInventoryView(),
InventoryType.SlotType.ARMOR, InventoryUtils.getArmorSlotId(slot), event.getClick(), action);
Bukkit.getPluginManager().callEvent(fakeEvent);
if (fakeEvent.isCancelled()) {
event.setCancelled(true);
return;
}
InventoryManager.updateArmor(player, inventory, slot, rawSlot, action, currentItem, cursor);
if (actionType == ActionType.GET) {
inventory.setItem(rawSlot, slot.getCup());
} else if (slot.isCup(currentItem)) {
player.setItemOnCursor(new ItemStack(Material.AIR));
}
player.updateInventory();
}
if (actionType == ActionType.DROP) {
new BukkitRunnable() {
@Override
public void run() {
inventory.setItem(rawSlot, slot.getCup());
player.updateInventory();
}
}.runTaskLater(RPGInventory.getInstance(), 1);
} else {
event.setCancelled(true);
}
}