本文整理汇总了Java中org.bukkit.inventory.PlayerInventory.setItemInMainHand方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInventory.setItemInMainHand方法的具体用法?Java PlayerInventory.setItemInMainHand怎么用?Java PlayerInventory.setItemInMainHand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.PlayerInventory
的用法示例。
在下文中一共展示了PlayerInventory.setItemInMainHand方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInteract
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
Player player = clickEvent.getPlayer();
PlayerInventory inventory = player.getInventory();
ItemStack mainHandItem;
if (mainHandSupported) {
mainHandItem = inventory.getItemInMainHand();
} else {
mainHandItem = inventory.getItemInHand();
}
if (isOurGraph(mainHandItem)) {
inventory.setItemInMainHand(new ItemStack(Material.AIR));
}
}
示例2: commandUse
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public boolean commandUse(CommandSender sender, String[] args) {
Variables var = Necessities.getVar();
if (sender instanceof Player) {
Player p = (Player) sender;
PlayerInventory inv = p.getInventory();
ItemStack hand = inv.getItemInMainHand();
ItemStack pants = inv.getLeggings();
if (hand.getType() != Material.AIR) {
inv.setLeggings(hand);
inv.setItemInMainHand(pants);
p.sendMessage(var.getMessages() + "Pants equipped.");
} else {
if (pants != null)
inv.setItemInMainHand(pants);
inv.setLeggings(new ItemStack(Material.AIR));
p.sendMessage(var.getMessages() + "Pants removed.");
}
} else
sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
return true;
}
示例3: commandUse
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public boolean commandUse(CommandSender sender, String[] args) {
Variables var = Necessities.getVar();
if (sender instanceof Player) {
Player p = (Player) sender;
PlayerInventory inv = p.getInventory();
ItemStack hand = inv.getItemInMainHand();
ItemStack hat = inv.getHelmet();
if (hand.getType() != Material.AIR) {
inv.setHelmet(hand);
inv.setItemInMainHand(hat);
p.sendMessage(var.getMessages() + "Hat equipped.");
} else {
if (hat != null)
inv.setItemInMainHand(hat);
inv.setHelmet(new ItemStack(Material.AIR));
p.sendMessage(var.getMessages() + "Hat removed.");
}
} else
sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
return true;
}
示例4: commandUse
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public boolean commandUse(CommandSender sender, String[] args) {
Variables var = Necessities.getVar();
if (sender instanceof Player) {
Player p = (Player) sender;
PlayerInventory inv = p.getInventory();
ItemStack hand = inv.getItemInMainHand();
ItemStack chestplate = inv.getChestplate();
if (hand.getType() != Material.AIR) {
inv.setChestplate(hand);
inv.setItemInMainHand(chestplate);
p.sendMessage(var.getMessages() + "Chestplate equipped.");
} else {
if (chestplate != null)
inv.setItemInMainHand(chestplate);
inv.setChestplate(new ItemStack(Material.AIR));
p.sendMessage(var.getMessages() + "Chestplate removed.");
}
} else
sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
return true;
}
示例5: commandUse
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
public boolean commandUse(CommandSender sender, String[] args) {
Variables var = Necessities.getVar();
if (sender instanceof Player) {
Player p = (Player) sender;
PlayerInventory inv = p.getInventory();
ItemStack hand = inv.getItemInMainHand();
ItemStack boots = inv.getBoots();
if (hand.getType() != Material.AIR) {
inv.setBoots(hand);
inv.setItemInMainHand(boots);
p.sendMessage(var.getMessages() + "Boots equipped.");
} else {
if (boots != null)
inv.setItemInMainHand(boots);
inv.setBoots(new ItemStack(Material.AIR));
p.sendMessage(var.getMessages() + "Boots removed.");
}
} else
sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have armor.");
return true;
}
示例6: removeSingleSignFromHand
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
private void removeSingleSignFromHand(Player player) {
if (player.getGameMode() == GameMode.CREATIVE) {
return;
}
PlayerInventory inventory = player.getInventory();
if (isOfType(inventory.getItemInMainHand(), Material.SIGN)) {
inventory.setItemInMainHand(removeOneItem(inventory.getItemInMainHand()));
} else if (isOfType(inventory.getItemInOffHand(), Material.SIGN)) {
inventory.setItemInOffHand(removeOneItem(inventory.getItemInOffHand()));
}
}
示例7: onBrewingClick
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBrewingClick(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
ItemStack itemstack = event.getItem();
if ((itemstack == null) || (itemstack.getType() != Material.BLAZE_POWDER)) {
return;
}
itemstack = itemstack.clone();
Block clicked = event.getClickedBlock();
BlockState state = clicked.getState();
if (!(state instanceof BrewingStand)) {
return;
}
BrewingStand stand = (BrewingStand) state;
ItemStack existing = stand.getInventory().getFuel();
if (existing != null) {
existing = existing.clone();
}
PlayerInventory inventory = event.getPlayer().getInventory();
switch (event.getHand()) {
case HAND: {
inventory.setItemInMainHand(existing);
break;
}
case OFF_HAND: {
inventory.setItemInOffHand(existing);
break;
}
default: {
throw new IllegalArgumentException("Unexpected hand slot in interaction: " + event.getHand());
}
}
stand.getInventory().setFuel(itemstack);
event.setCancelled(true);
}
示例8: onPlayerInteract
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
/**
* Handle player interactions:
* <ul>
* <li>Launch TNT if permitted and gliding.</li>
* <li>Set gliding if player right clicks a rocket while in the air and
* wearing elytra, to compensate for NCP's interference.</li>
* </ul>
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
// Only handle left and right click air events
Action action = event.getAction();
if (action != Action.LEFT_CLICK_AIR && action != Action.RIGHT_CLICK_AIR) {
return;
}
// Assisted takeoff if wearing unbroken elytra.
// NOTE: event.getItem() allows off hand use.
if (action == Action.RIGHT_CLICK_AIR &&
event.getItem().getType() == Material.FIREWORK &&
!player.isOnGround() &&
player.getVehicle() == null &&
isWearingElytra(player, true)) {
Block feetBlock = player.getLocation().getBlock();
if (feetBlock != null && canAssistedTakeOffFrom(feetBlock.getType())) {
PlayerState state = getState(player);
state.setTakingOff();
player.setGliding(true);
}
}
// Only throw TNT if permitted, gliding and holding TNT.
PlayerInventory inventory = player.getInventory();
ItemStack stack = inventory.getItemInMainHand();
if (!player.hasPermission("wingcommander.tnt") ||
!player.isGliding() ||
stack.getType() != Material.TNT) {
return;
}
// Use up a TNT.
int amount = stack.getAmount() - 1;
if (amount > 1) {
stack.setAmount(amount);
} else {
inventory.setItemInMainHand(null);
}
// Spawn TNT.
Entity tnt = player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT);
if (action == Action.LEFT_CLICK_AIR) {
// Throw the TNT forward.
Vector TNTVelocity = player.getLocation().getDirection();
TNTVelocity.normalize();
TNTVelocity.multiply(WingCommander.CONFIG.TNT_THROW_SPEED);
TNTVelocity.add(player.getVelocity());
tnt.setVelocity(TNTVelocity);
} else if (action == Action.RIGHT_CLICK_AIR) {
// Drop the TNT with current velocity.
tnt.setVelocity(player.getVelocity());
}
}
示例9: onPlayerShoot
import org.bukkit.inventory.PlayerInventory; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerShoot(PlayerInteractEvent e) {
Action action = e.getAction();
if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return;
Player player = e.getPlayer();
if(!isEnabled(player.getWorld())) return;
if(e.getMaterial() != Material.ENDER_PEARL) return;
if (e.isCancelled()) return;
e.setCancelled(true);
EnderPearl pearl = player.launchProjectile(EnderPearl.class);
pearl.setVelocity(player.getEyeLocation().getDirection().multiply(2));
GameMode mode = player.getGameMode();
if(mode == GameMode.ADVENTURE || mode == GameMode.SURVIVAL) {
PlayerInventory inv = player.getInventory();
boolean isInOffhand = true;
ItemStack hand = inv.getItemInOffHand();
if(hand.getType() != Material.ENDER_PEARL) {
hand = inv.getItemInMainHand();
isInOffhand = false;
}
hand.setAmount(hand.getAmount() - 1);
if(isInOffhand)
inv.setItemInOffHand(hand);
else
inv.setItemInMainHand(hand);
}
}