本文整理汇总了Java中org.bukkit.inventory.EquipmentSlot.OFF_HAND属性的典型用法代码示例。如果您正苦于以下问题:Java EquipmentSlot.OFF_HAND属性的具体用法?Java EquipmentSlot.OFF_HAND怎么用?Java EquipmentSlot.OFF_HAND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bukkit.inventory.EquipmentSlot
的用法示例。
在下文中一共展示了EquipmentSlot.OFF_HAND属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onWalkieTalkieInteract
@EventHandler
public void onWalkieTalkieInteract(PlayerInteractEvent e) {
if (e.getPlayer().getInventory().getItemInMainHand().getType() != Material.REDSTONE_COMPARATOR)
return;
if (e.getHand() == EquipmentSlot.OFF_HAND)
return;
WalkieTalkie wt = new WalkieTalkie(main,
main.getPlayerManager().getPlayer(e.getPlayer()).getCurrentWalkieTalkieFrequency());
// Left click to tune frequency.
if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (e.getPlayer().isSneaking()) {
wt.decreaseFrequency(e.getPlayer());
} else {
wt.increaseFrequency(e.getPlayer());
}
}
}
示例2: getEquipmentSlot
private static EquipmentSlot getEquipmentSlot(String slotName) {
if (!slotName.startsWith("slot.")) {
slotName = "slot." + slotName;
}
EquipmentSlot equipmentSlot = null;
String[] path = slotName.split("\\.");
if (path.length == 3) {
if (path[1].equalsIgnoreCase("armor")) {
equipmentSlot = EquipmentSlot.valueOf(Strings.getTechnicalName(path[2]));
} else if (path[1].equalsIgnoreCase("weapon")) {
if (path[2].equalsIgnoreCase("mainhand")) {
equipmentSlot = EquipmentSlot.HAND;
}
if (path[2].equalsIgnoreCase("offhand")) {
equipmentSlot = EquipmentSlot.OFF_HAND;
}
}
}
return equipmentSlot;
}
示例3: callBlockPlaceEvent
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityHuman who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
CraftWorld craftWorld = world.getWorld();
CraftServer craftServer = world.getServer();
Player player = (Player) who.getBukkitEntity();
Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
Block placedBlock = replacedBlockState.getBlock();
boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());
org.bukkit.inventory.ItemStack item;
EquipmentSlot equipmentSlot;
if (hand == EnumHand.MAIN_HAND) {
item = player.getInventory().getItemInMainHand();
equipmentSlot = EquipmentSlot.HAND;
} else {
item = player.getInventory().getItemInOffHand();
equipmentSlot = EquipmentSlot.OFF_HAND;
}
BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot);
craftServer.getPluginManager().callEvent(event);
return event;
}
示例4: onPlayerLeaverInteract
@EventHandler
public void onPlayerLeaverInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
Block clicked = e.getClickedBlock();
if (clicked == null)
return;
Block underneath = clicked.getRelative(BlockFace.DOWN);
Location underneathLoc = underneath.getLocation();
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || e.getHand() == EquipmentSlot.OFF_HAND)
return;
if (clicked.getType() != Material.LEVER || underneath == null)
return;
String chunk = clicked.getLocation().getChunk().getX() + ";" + clicked.getLocation().getChunk().getZ();
if (underneath.getType() == Material.SPONGE && !underneath.isBlockPowered()) {
if (!main.getGeckManager().isGeckBuildCorrect(underneath)) {
p.sendMessage(ChatColor.RED + "You must build the GECK correctly!");
// Check if the geck is inside the powerables list
} else if (main.getGenListener().getPowerable().get(clicked.getWorld().getName()).getList(chunk)
.contains(underneathLoc)) {
main.getGeckObjectManager().addGeckLocation(underneathLoc);
main.getGeckObjectManager().getGeckObject(underneathLoc).setCorrect(true);
main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(true);
p.sendMessage(ChatColor.GREEN + "GECK Enabled!");
return;
}
} else if (main.getGeckObjectManager().getGeckObject(underneathLoc) != null && underneath.isBlockPowered()) {
main.getGeckObjectManager().getGeckObject(underneathLoc).setPowered(false);
main.getGeckObjectManager().removeGeckLocation(underneathLoc);
p.sendMessage(ChatColor.RED + "GECK Disabled!");
}
}
示例5: getSlotWithItemStack
private EquipmentSlot getSlotWithItemStack(PlayerInventory inventory, ItemStack brokenItem)
{
if(itemsAreSimilar(inventory.getItemInMainHand(), brokenItem, false))
{
return EquipmentSlot.HAND;
}
if(itemsAreSimilar(inventory.getItemInOffHand(), brokenItem, false))
{
return EquipmentSlot.OFF_HAND;
}
return null;
}
示例6: tryRefillStackInHand
@SuppressWarnings("deprecation")
private void tryRefillStackInHand(Player player, EquipmentSlot slot, boolean dataValueMatters)
{
if(slot == null) return;
if(!featureEnabled(Features.RefillStacks, player)) return;
ItemStack stack = null;
int slotIndex = 0;
if(slot == EquipmentSlot.HAND)
{
stack = player.getInventory().getItemInMainHand();
slotIndex = player.getInventory().getHeldItemSlot();
}
else if(slot == EquipmentSlot.OFF_HAND)
{
stack = player.getInventory().getItemInOffHand();
slotIndex = 40;
}
else
{
return;
}
if(AutomaticInventory.instance.config_noAutoRefillIDs.contains(stack.getTypeId())) return;
if(!dataValueMatters || stack.getAmount() == 1)
{
PlayerInventory inventory = player.getInventory();
AutomaticInventory.instance.getServer().getScheduler().scheduleSyncDelayedTask(
AutomaticInventory.instance,
new AutoRefillHotBarTask(player, inventory, slotIndex, stack.clone(), dataValueMatters),
2L);
}
}
示例7: onHammerSwing
@EventHandler
public void onHammerSwing(PlayerInteractEvent e) {
if (state != State.RUNNING)
return;
if (isWrongTool)
return;
if (e.getHand() == EquipmentSlot.OFF_HAND)
return;
if (!e.getPlayer().getUniqueId().equals(player.getPlayer().getUniqueId()))
return;
e.setCancelled(true);
if (skill.isAnvil(e.getClickedBlock())) {
doAnvilClick(e);
return;
}
if (skill.isCutter(e.getClickedBlock())) {
doCutClick(e);
return;
}
Set<Material> s = null;
List<Block> sight = e.getPlayer().getLineOfSight(s, 4);
for (Block block : sight) {
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) {
doLavaClick(e);
return;
}
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
doWaterClick(e);
return;
}
}
}
示例8: onPlayerClickPlayer
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerClickPlayer(PlayerInteractEntityEvent event) {
if(ConfigManager.getServerVersion().isNewerThan(ConfigManager.ServerVersion.MINECRAFT_1_8_R3) && event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
Player player = event.getPlayer();
if((event.getRightClicked() instanceof Player) && player.isSneaking()) {
if(Permission.NOVAGUILDS_PLAYERINFO.has(player)) {
NovaPlayer nCPlayer = PlayerManager.getPlayer(event.getRightClicked());
plugin.getPlayerManager().sendPlayerInfo(player, nCPlayer);
}
}
}
示例9: onPlayerInteract
/**
* Prevents access to containers.
*
* @param event
* The event object.
*/
@EventHandler(ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Player player = event.getPlayer();
Block block = event.getClickedBlock();
boolean clickedSign = block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN;
// When using the offhand check, access checks must still be performed,
// but no messages must be sent
boolean usedOffHand = event.getHand() == EquipmentSlot.OFF_HAND;
Optional<Protection> protection = plugin.getProtectionFinder().findProtection(block,
SearchMode.NO_SUPPORTING_BLOCKS);
if (!protection.isPresent()) {
if (tryPlaceSign(event.getPlayer(), block, event.getBlockFace(), SignType.PRIVATE)) {
plugin.getTranslator().sendMessage(player, Translation.PROTECTION_CLAIMED_CONTAINER);
event.setCancelled(true);
}
return;
}
// Check if protection needs update
plugin.getProtectionUpdater().update(protection.get(), false);
// Check if player is allowed
if (checkAllowed(player, protection.get(), clickedSign)) {
handleAllowed(event, protection.get(), clickedSign, usedOffHand);
} else {
handleDisallowed(event, protection.get(), clickedSign, usedOffHand);
}
}
示例10: getEquipmentSlot
public static EquipmentSlot getEquipmentSlot(String slotName) {
if (!slotName.startsWith("slot.")) slotName = "slot." + slotName;
EquipmentSlot equipmentSlot = null;
String[] path = slotName.split("\\.");
if (path.length != 3) return null;
if (path[1].equalsIgnoreCase("armor")) {
equipmentSlot = EquipmentSlot.valueOf(Strings.getTechnicalName(path[2]));
} else if (path[1].equalsIgnoreCase("weapon")) {
if (path[2].equalsIgnoreCase("mainhand")) equipmentSlot = EquipmentSlot.HAND;
if (path[2].equalsIgnoreCase("offhand")) equipmentSlot = EquipmentSlot.OFF_HAND;
}
return equipmentSlot;
}
示例11: callPlayerInteractEvent
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, BlockPosition position, EnumDirection direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
Player player = (who == null) ? null : (Player) who.getBukkitEntity();
CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
CraftWorld craftWorld = (CraftWorld) player.getWorld();
CraftServer craftServer = (CraftServer) player.getServer();
Block blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
if (position.getY() > 255) {
blockClicked = null;
switch (action) {
case LEFT_CLICK_BLOCK:
action = Action.LEFT_CLICK_AIR;
break;
case RIGHT_CLICK_BLOCK:
action = Action.RIGHT_CLICK_AIR;
break;
}
}
if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
itemInHand = null;
}
PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
if (cancelledBlock) {
event.setUseInteractedBlock(Event.Result.DENY);
}
craftServer.getPluginManager().callEvent(event);
return event;
}
示例12: OffHand
protected OffHand() {
super("weapon.offhand", 40, EquipmentSlot.OFF_HAND);
}
示例13: onPlayerInteract
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.useItemInHand() == Event.Result.DENY) return;
Player player = event.getPlayer();
FawePlayer<Object> fp = FawePlayer.wrap(player);
if (fp.getMeta("CFISettings") == null) return;
try {
if (event.getHand() == EquipmentSlot.OFF_HAND) return;
} catch (NoSuchFieldError | NoSuchMethodError ignored) {}
List<Block> target = player.getLastTwoTargetBlocks((Set<Material>) null, 100);
if (target.isEmpty()) return;
Block targetBlock = target.get(0);
World world = player.getWorld();
mutable.setWorld(world);
mutable.setX(targetBlock.getX() + 0.5);
mutable.setY(targetBlock.getY() + 0.5);
mutable.setZ(targetBlock.getZ() + 0.5);
Collection<Entity> entities = world.getNearbyEntities(mutable, 0.46875, 0, 0.46875);
if (!entities.isEmpty()) {
Action action = event.getAction();
boolean primary = action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
double minDist = Integer.MAX_VALUE;
ItemFrame minItemFrame = null;
for (Entity entity : entities) {
if (entity instanceof ItemFrame) {
ItemFrame itemFrame = (ItemFrame) entity;
Location loc = itemFrame.getLocation();
double dx = loc.getX() - mutable.getX();
double dy = loc.getY() - mutable.getY();
double dz = loc.getZ() - mutable.getZ();
double dist = dx * dx + dy * dy + dz * dz;
if (dist < minDist) {
minItemFrame = itemFrame;
minDist = dist;
}
}
}
if (minItemFrame != null) {
handleInteract(event, minItemFrame, primary);
if (event.isCancelled()) return;
}
}
}
示例14: onNPCClick
/**
* This checks if the player clicked on valid NPC, and starts the
* conversation
*
* @param event
* PlayerInteractEvent
*/
@EventHandler
public void onNPCClick(final PlayerInteractEvent event) {
try {
// Only fire the event for the main hand to avoid that the event is triggered two times.
if (event.getHand() == EquipmentSlot.OFF_HAND && event.getHand() != null) {
return; // off hand packet, ignore.
}
} catch (LinkageError e) {
// it's fine, 1.8 doesn't trigger this event twice
}
if (event.isCancelled()) {
return;
}
// check if the player has required permission
if (!event.getPlayer().hasPermission("betonquest.conversation")) {
return;
}
// check if the blocks are placed in the correct way
String conversationID = null;
if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
&& event.getClickedBlock().getType().equals(Material.SKULL)) {
Block block = event.getClickedBlock().getLocation().clone().add(0, -1, 0).getBlock();
if (block.getType().equals(Material.STAINED_CLAY)) {
Block[] signs = new Block[] { block.getRelative(BlockFace.EAST), block.getRelative(BlockFace.WEST),
block.getRelative(BlockFace.NORTH), block.getRelative(BlockFace.SOUTH) };
Sign theSign = null;
byte count = 0;
for (Block sign : signs) {
if (sign.getType().equals(Material.WALL_SIGN) && sign.getState() instanceof Sign) {
theSign = (Sign) sign.getState();
count++;
}
}
if (count == 1 && theSign != null && theSign.getLine(0).equalsIgnoreCase("[NPC]")) {
conversationID = theSign.getLine(1);
}
}
}
// if the conversation ID was extracted from NPC then start the
// conversation
if (conversationID != null) {
String assignment = Config.getNpc(conversationID);
if (assignment != null) {
if (CombatTagger.isTagged(PlayerConverter.getID(event.getPlayer()))) {
Config.sendMessage(PlayerConverter.getID(event.getPlayer()), "busy");
return;
}
event.setCancelled(true);
new Conversation(PlayerConverter.getID(event.getPlayer()), assignment,
event.getClickedBlock().getLocation().add(0.5, -1, 0.5));
} else {
Debug.error("Cannot start conversation: nothing assigned to " + conversationID);
return;
}
}
}