Java 类org.bukkit.inventory.EquipmentSlot 实例源码

项目:MT_Communication    文件:WalkieTalkieListener.java   
@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());
        }
    }

}
项目:MT_Communication    文件:WalkieTalkieListener.java   
@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());
        }
    }

}
项目:ZentrelaRPG    文件:ItemManager.java   
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    ItemStack item = event.getPlayer().getEquipment().getItemInMainHand();
    if (event.getHand() == EquipmentSlot.HAND && item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
        String name = item.getItemMeta().getDisplayName();
        if (itemNameToIdentifierMap.containsKey(name)) {
            String identifier = itemNameToIdentifierMap.get(name);
            if (itemIdentifierToRunnableMap.containsKey(identifier)) {
                PlayerDataRPG pd = plugin.getPD(p);
                if (pd != null)
                    itemIdentifierToRunnableMap.get(identifier).run(event, p, pd);
                event.setCancelled(true);
            }
        }
    }
}
项目:AddGun    文件:StandardGun.java   
/**
 * Computes chance that the gun misfires! Yikes.
 * 
 * Misfire is based on when you last repaired the gun. A misfire has a chance of causing a gun to explode (handled in another function)
 * 
 * 
 * 
 * @param entity the entity shooting the gun
 * @param bulletType the type of bullet
 * @param item the gunItem, could be modified by this.
 * @param gunData the gunData
 * @param hand the hand holding the gun.
 * 
 * @return true if misfired, false otherwise.
 */
public boolean misfire(LivingEntity entity, Bullet bulletType, ItemStack item, Map<String, Object> gunData,
        EquipmentSlot hand) {
    if (entity == null || !enabled) 
        return true;

    Integer health = (Integer) gunData.get("health"); // gunhealth!
    double misfireChance = 1.0d - sigmoid((double) health, (double) this.middleRisk,0.5d, (double) this.riskSpread);

    double random = Math.random();
    AddGun.getPlugin().debug("Misfire computation: {0} health {1} misfireChance {2} random", health, misfireChance, random);
    if (random < misfireChance) {
        return true;
    }
    return false;
}
项目:Bags2    文件:BagEnchant.java   
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    Player p = e.getPlayer();
    if(hasPermission(enchant_open, p))
    {   

    Location loc = new Location(p.getWorld(), 10000.0D, 255.0D, 10000.0D);
    //Can't be handled differently :(
    Block im5 = loc.getBlock();
       if(im5.getType() != Material.ENCHANTMENT_TABLE)
       {
          im5.setType(Material.ENCHANTMENT_TABLE);
       }

       p.openEnchanting(loc, true);
    }
    super.onInteract(e, es);
}
项目:Bags2    文件:BagStorage.java   
@Override
    public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
    {
        if(es.equals(EquipmentSlot.HAND))
        {   
        Player p = e.getPlayer();

        ItemStack stack = es.equals(EquipmentSlot.HAND) ? p.getInventory().getItemInMainHand() : p.getInventory().getItemInOffHand();
        ItemStack[] istack = loadInventory(getCompoundOfItemStack(stack), size);
        CInventory inv = Bags2.bagGUI.createInventory(stack.getItemMeta().getDisplayName(), istack, size);
//      inv.slot = p.getInventory().getHeldItemSlot();
//      p.openInventory(inv.getInternalInventory());

        inv.openInventory(p);
        }
        super.onInteract(e, es);
    }
项目:Bags2    文件:BagBase.java   
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    ItemStack stack = es.equals(EquipmentSlot.HAND) ? e.getPlayer().getInventory().getItemInMainHand() : e.getPlayer().getInventory().getItemInOffHand();
    if(stack.hasItemMeta() ? !stack.getItemMeta().getDisplayName().equals(Translation.get(name)) : false)
    {
        if(stack.getItemMeta().getDisplayName().startsWith(ChatColor.RESET.toString()))
        {

            ItemMeta im = stack.getItemMeta();
            if(!im.getDisplayName().startsWith(ChatColor.ITALIC.toString()))
            im.setDisplayName(ChatColor.RESET + Translation.get(name));
            stack.setItemMeta(im);
            if(es.equals(EquipmentSlot.HAND))
            e.getPlayer().getInventory().setItemInMainHand(stack);
            else
            e.getPlayer().getInventory().setItemInOffHand(stack);
        }
    }
    super.onInteract(e, es);
}
项目:Transport-Pipes    文件:HitboxUtils.java   
/**
 * "simulate" a block place when you click on the side of a duct
 */
public static boolean placeBlock(Player p, Block b, Block placedAgainst, int id, byte data, EquipmentSlot es) {
    if (!DuctUtils.canBuild(p, b, placedAgainst, es)) {
        return false;
    }
    // check if there is already a duct at this position

    Map<BlockLoc, Duct> ductMap = TransportPipes.instance.getDuctMap(b.getWorld());
    if (ductMap != null) {
        if (ductMap.containsKey(BlockLoc.convertBlockLoc(b.getLocation()))) {
            return false;
        }
    }

    if (!(b.getType() == Material.AIR || b.isLiquid())) {
        return false;
    }
    b.setTypeIdAndData(id, data, true);

    if (TransportPipes.instance.containerBlockUtils.isIdContainerBlock(id)) {
        TransportPipes.instance.containerBlockUtils.updateDuctNeighborBlockSync(b, true);
    }

    return true;
}
项目:MCLibrary    文件:ClickWizard.java   
@Override
protected Listener listener(Consumer<Block> callback) {
    return new Listener() {
        @EventHandler
        public void onClick(PlayerInteractEvent event) {
            Player clicker = event.getPlayer();
            EquipmentSlot hand = event.getHand();
            Block block = event.getClickedBlock();

            if (block != null && clicker.equals(player)
                    && (!MCUtils.isOffHandSupport() || hand == EquipmentSlot.HAND)) {
                clicker.sendMessage(MCUtils.colorize(messageFunc.apply(block)));
                callback.accept(block);
                event.setCancelled(true);
            }
        }
    };
}
项目:MCLibrary    文件:LibraryCommand.java   
public static void init(MCLibrary plugin) {
    Bukkit.getPluginManager().registerEvents(new Listener() {
        @EventHandler
        @SuppressWarnings("deprecation")
        public void onInteract(PlayerInteractEvent event) {
            if (MCUtils.isOffHandSupport() && event.getHand() != EquipmentSlot.HAND)
                return;

            Player player = event.getPlayer();
            Block block = event.getClickedBlock();
            if (block == null || !INFO_LISTENERS.contains(player))
                return;

            Location loc = block.getLocation();
            CommandSenderWrapper wrapper = new CommandSenderWrapper(player);
            wrapper.sendMessage("---------------------------------------------");
            wrapper.sendMessage("&eworld: &f" + loc.getWorld().getName());
            wrapper.sendMessage(String.format("&ex: &f%s (%s)", loc.getBlockX(), loc.getX()));
            wrapper.sendMessage(String.format("&ey: &f%s (%s)", loc.getBlockY(), loc.getY()));
            wrapper.sendMessage(String.format("&ez: &f%s (%s)", loc.getBlockZ(), loc.getZ()));
            wrapper.sendMessage(String.format("&eblock: &f%s:%s (%s)", block.getTypeId(), block.getData(), block.getType().name()));
        }
    }, plugin);
}
项目:DragonEggDrop    文件:PortalClickListener.java   
@EventHandler
public void onClickEndPortalFrame(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    World world = player.getWorld();
    Block clickedBlock = event.getClickedBlock();
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK || world.getEnvironment() != Environment.THE_END 
            || clickedBlock.getType() != Material.BEDROCK || event.getHand() != EquipmentSlot.HAND
            || (player.getInventory().getItemInMainHand() != null || player.getInventory().getItemInOffHand() != null)) return;

    NMSAbstract nmsAbstract = plugin.getNMSAbstract();
    DragonBattle dragonBattle = nmsAbstract.getEnderDragonBattleFromWorld(world);
    Location portalLocation = dragonBattle.getEndPortalLocation();

    if (event.getClickedBlock().getLocation().distanceSquared(portalLocation) > 36) return; // 5 blocks

    EndWorldWrapper endWorld = plugin.getDEDManager().getWorldWrapper(world);
    int secondsRemaining = endWorld.getTimeUntilRespawn();
    if (secondsRemaining <= 0) return;

    plugin.sendMessage(player, "Dragon will respawn in " + ChatColor.YELLOW + secondsRemaining);
}
项目:Cardinal    文件:DocumentItems.java   
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;
}
项目:MysteryBags    文件:MysteryBagsListener.java   
@EventHandler
public void onInteract(PlayerInteractEvent e) {
    if (e.getAction().toString().charAt(0) == 'R') {
        Player p = e.getPlayer();
        ItemStack i = e.getItem();

        if (i == null)
            return;

        Hand hand = e.getHand() == EquipmentSlot.HAND ? Hand.MAIN : Hand.OFF;
        List<String> lore = i.getItemMeta().getLore();
        if (lore != null && lore.size() > 0) {
            String id = lore.get(0).replace("�", "");
            MysteryBag bag = instance.cheezBags.get(id);
            if (bag != null) {
                e.setCancelled(true);
                if (p.hasPermission("mysterybags.open"))
                    bag.open(e.getPlayer(), hand);
                else
                    p.sendMessage(MysteryBags.PREFIX + "�7You do not have permission to open that.");
            }
        }
    }
}
项目:ArmorStandEditor    文件:PlayerEditorManager.java   
boolean canEdit(Player player, ArmorStand as){
    ignoreNextInteract = true;
    ArrayList<Event> events = new ArrayList<Event>();
    events.add(new PlayerInteractEntityEvent(player, as, EquipmentSlot.HAND));
    events.add(new PlayerInteractAtEntityEvent(player, as, as.getLocation().toVector(), EquipmentSlot.HAND));
    //events.add(new PlayerArmorStandManipulateEvent(player, as, player.getEquipment().getItemInMainHand(), as.getItemInHand(), EquipmentSlot.HAND));
    for(Event event : events){
        if(!(event instanceof Cancellable)) continue;
        try{
            plugin.getServer().getPluginManager().callEvent(event);
        } catch(IllegalStateException ise){
            ise.printStackTrace();
            ignoreNextInteract = false;
            return false; //Something went wrong, don't allow edit just in case
        }
        if(((Cancellable)event).isCancelled()){
            ignoreNextInteract = false;
            return false;
        }
    }
    ignoreNextInteract = false;
    return true;
}
项目:BlockLocker    文件:InteractListener.java   
private boolean allowedByBlockPlaceEvent(Block placedBlock, BlockState replacedBlockState, Block placedAgainst,
        Player player) {
    Material originalMaterial = placedBlock.getType();

    BlockPlaceEvent placeEvent = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst,
            player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND);
    Bukkit.getPluginManager().callEvent(placeEvent);

    Material placedMaterial = placeEvent.getBlockPlaced().getType();
    if (placeEvent.isCancelled() || !placedMaterial.equals(originalMaterial)) {
        // We consider the event cancelled too when the placed block was
        // changed
        return false;
    }
    return true;
}
项目:StarQuestCode    文件:EventSimulator.java   
/**
    * Function for a moving machina to test whether it's allowed to move to a
    * new location by protection plugins. Returns true if the player could
    * build (and break) the new block.
    * 
    * This function will fire a blockplace event, collect the cancelled result
    * at the highest possible priority, then cancel its own event to prevent it
    * from being logged by any monitoring plugins.
    * 
    * @param target
    *            The target location to place at
    * @param typeId
    *            The typeId of the block to place
    * @param placedAgainst
    *            The block that it will be placed against
    * @param player
    *            The player to simulate for
    * @return True if the player may place a block at the location
    */
   @SuppressWarnings("deprecation")
public static boolean blockPlacePretend(BlockLocation target, int typeId, BlockLocation placedAgainst, Player player) {
       Block placedBlock = target.getBlock();
       BlockState replacedBlockState = placedBlock.getState();
       int oldType = replacedBlockState.getTypeId();
       byte oldData = replacedBlockState.getRawData();

       // Set the new state without physics.
       placedBlock.setTypeIdAndData(typeId, (byte) 0, false);

       pretendEvent = new ArtificialBlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst.getBlock(), new ItemStack(Material.AIR), player, true, EquipmentSlot.HAND);
       pretendEventCancelled = true;
       MachinaCore.pluginManager.callEvent(pretendEvent);

       // Revert to the old state without physics.
       placedBlock.setTypeIdAndData(oldType, oldData, false);

       return !pretendEventCancelled;
   }
项目:BetonQuest    文件:QuestItemHandler.java   
@SuppressWarnings("deprecation")
   @EventHandler
public void onItemFrameClick(PlayerInteractEntityEvent event) {
    if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
        return;
    }
    // this prevents the journal from being placed inside of item frame
    if (event.getRightClicked() instanceof ItemFrame) {
        ItemStack item = null;
        try {
            item = (event.getHand() == EquipmentSlot.HAND) ? event.getPlayer().getInventory().getItemInMainHand() : event.getPlayer().getInventory().getItemInOffHand();
        } catch (LinkageError e) {
            item = event.getPlayer().getItemInHand();
        }
        String playerID = PlayerConverter.getID(event.getPlayer());
        if (Journal.isJournal(playerID, item) || Utils.isQuestItem(item)) {
            event.setCancelled(true);
        }
    }
}
项目:SpigotSource    文件:CraftEventFactory.java   
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;
}
项目:uppercore    文件:HotbarManager.java   
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
    try {
        if (e.getHand() != EquipmentSlot.HAND)
            return;
    } catch (Error ignored) {
    }
    if (e.getAction() != Action.PHYSICAL)
        onClick(e); // this method cancels the event by himself
}
项目:AddGun    文件:StandardGun.java   
/**
 * Gets chance that the misfiring gun also explodes! Yikes.
 * 
 * @param entity the entity shooting the gun
 * @param bulletType the type of bullet
 * @param item the gunItem, could be modified by this.
 * @param gunData the gunData
 * @param hand the hand holding the gun.
 * @return true if blowout, false otherwise
 */
public boolean blowout(LivingEntity entity, Bullet bulletType, ItemStack gun, Map<String, Object> gunData,
        EquipmentSlot hand) {
    if (entity == null || !enabled)
        return true;

    double random = Math.random();
    if (random < this.misfireBlowoutChance) {
        Location explosion = entity.getLocation().clone().add(0.0d, 1.3d, 0.0d);
        World world = explosion.getWorld();
        random = Math.random();
        world.createExplosion(explosion.getX(), explosion.getY(), explosion.getZ(), this.baseBlowoutStrength + bulletType.getExplosionLevel(), (random < bulletType.getFireChance()) ? true : false, true);

        gunData.clear();
        gunData.put("health", Integer.valueOf(0));
        gun = updateGunLore(updateGunData(gun, gunData));
        switch(hand) {
        case HAND:
            entity.getEquipment().setItemInMainHand(gun);
            break;
        case OFF_HAND:
            entity.getEquipment().setItemInOffHand(gun);
            break;
        default:
        }

        return true;
    }
    return false;
}
项目:WC    文件:PlayerEvent.java   
@EventHandler
public void onInteract(PlayerInteractEvent e){
    Player p = e.getPlayer();
    Block b;

    if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getHand() == EquipmentSlot.HAND){
        b = e.getClickedBlock();

        if (plugin.getCasinos().contains(b.getLocation())){
            e.setCancelled(true);
            FichasMenu.openInventory(p);
        }
    }
}
项目:WC    文件:SpawnMob.java   
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSpawn(PlayerInteractEvent e){
    Player p = e.getPlayer();

    if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(e.getHand() != EquipmentSlot.HAND) return;
        if (e.getItem() == null || !e.getItem().hasItemMeta() || !e.getItem().getItemMeta().hasDisplayName() || e.getItem().getType() != Material.MONSTER_EGG) return;
        if (!ChatColor.stripColor(e.getItem().getItemMeta().getDisplayName()).contains("Spawn")) return;
        if (!files.getConfig().getStringList("mundosPermitidos").contains(p.getLocation().getWorld().getName())) {
            p.sendMessage(this.plugin.getPrefix() + ChatColor.RED + "No se puede usar en este mundo");
            return;
        }
        int id = Integer.parseInt(e.getItem().getItemMeta().getLore().get(0));
        String s = e.getItem().getItemMeta().getLore().get(1);

        RegionManager m = WGBukkit.getPlugin().getRegionManager(p.getWorld());
        if (m != null) {
            m.getApplicableRegions(p.getLocation()).getRegions().forEach(re ->{
                if (re != null && re.getOwners().contains(p.getUniqueId())) {
                    return;
                }
            });
        }

        SNMob mob = new SNMob(p);
        if (!mob.isOwner(id)) {
           p.sendMessage(SafariNet.getInstance().getPrefix() + ChatColor.RED + "No eres el dueño de este huevo");
            return;
        }
        mob.spawnMob(id, s);
        p.getInventory().getItemInMainHand().setAmount(-1);
    }
}
项目:WC    文件:Weapons.java   
@EventHandler
public void onInteract(PlayerInteractEvent e){
    Player p = e.getPlayer();
    Weapon weapon;

    if (e.getItem() == null || e.getHand() != EquipmentSlot.HAND) return;

    if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
        if (e.getItem().getType() == Material.POTION) return;
        if (e.getItem() == null || Weapon.getWeaponByItemStack(e.getItem()) == null || !Weapon.isWeapon(e.getItem())) return;
        weapon = Weapon.getWeaponByItemStack(e.getItem());

        if (weapon != null) e.setCancelled(true);
        if (weapon == null) return;

        weapon.shoot(p);
        return;
    }

    if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK){
        if (e.getItem() == null || Weapon.getWeaponByItemStack(e.getItem()) == null || !Weapon.isWeapon(e.getItem())) return;
        weapon = Weapon.getWeaponByItemStack(e.getItem());

        if (weapon != null) e.setCancelled(true);
        if (weapon == null) return;

        if (weapon.getId() == 0) return;

        weapon.watch(p);
    }
}
项目:Bags2    文件:BagEnder.java   
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    if(hasPermission(ender_open, e.getPlayer()))
    {   
    e.getPlayer().openInventory(e.getPlayer().getEnderChest());
    }
    super.onInteract(e, es);
}
项目:Bags2    文件:BagAnvil.java   
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    if(hasPermission(anvil_open, e.getPlayer()))
    {   
    Util.openAnvil(e.getPlayer());
    }
    super.onInteract(e, es);
}
项目:Bags2    文件:BagCrafting.java   
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    if(hasPermission(crafting_open, e.getPlayer()))
    {   
    e.getPlayer().openInventory(Bukkit.createInventory(e.getPlayer(), InventoryType.WORKBENCH, "Crafting Bag"));
    }
    super.onInteract(e, es);
}
项目:ProjectAres    文件:XMLUtils.java   
public static EquipmentSlot parseEquipmentSlot(Node node) throws InvalidXMLException {
    final EquipmentSlot slot = parsePlayerSlot(node).toEquipmentSlot();
    if(slot == null) {
        throw new InvalidXMLException("Not an equipment slot", node);
    }
    return slot;
}
项目:ProjectAres    文件:NMSHacks.java   
public static void useEntity(Player user, Entity target, boolean attack, EquipmentSlot hand) {
    ((CraftPlayer) user).getHandle().playerConnection.a(new PacketPlayInUseEntity(
        target.getEntityId(),
        attack ? PacketPlayInUseEntity.EnumEntityUseAction.ATTACK : PacketPlayInUseEntity.EnumEntityUseAction.INTERACT,
        null,
        hand == EquipmentSlot.OFF_HAND ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND
    ));
}
项目:MystiCraft    文件:SimpleWand.java   
@Override
public void onInteract(Player clicker, Action action, EquipmentSlot hand, ItemStack i) {
    String boundSpell = getBoundSpell(i.getItemMeta().getDisplayName());
    if (boundSpell.equals("none")) {
        clicker.sendMessage(ChatColor.RED + "You need to bind a spell with /bind <spell>");
        return;
    }
    Caster c = MystiCraft.getCasterManager().getCaster(clicker);
    if (!c.getKnowledge().isSpellKnown(boundSpell)) {
        clicker.sendMessage(ChatColor.RED + "You do not know " + boundSpell);
        return;
    }
    MystiCraft.getCasterManager().cast(c, boundSpell, CastSource.WAND);
}
项目:Debuggery    文件:InputFormatterTest.java   
@Test
public void testValueFromEnum() throws InputException {
    Class[] inputTypes = {
            WeatherType.class,
            EquipmentSlot.class,
            MainHand.class,
            PermissionDefault.class
    };

    String[] input = {
            "downfall",
            "HeAd",
            "lEfT",
            "NOT_OP"
    };

    Object[] output = InputFormatter.getTypesFromInput(inputTypes, Arrays.asList(input), null);

    // First let's make sure we didn't lose anything, or get anything
    assertEquals(inputTypes.length, output.length);

    // Next let's make sure everything is the right type
    assertTrue(output[0] instanceof WeatherType);
    assertTrue(output[1] instanceof EquipmentSlot);
    assertTrue(output[2] instanceof MainHand);
    assertTrue(output[3] instanceof PermissionDefault);

    // Finally, let's make sure the values are correct
    assertSame(output[0], WeatherType.DOWNFALL);
    assertSame(output[1], EquipmentSlot.HEAD);
    assertSame(output[2], MainHand.LEFT);
    assertSame(output[3], PermissionDefault.NOT_OP);
}
项目:MiniWynn    文件:SpellListener.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void on(PlayerInteractEvent event){
    Player player = event.getPlayer();
    if(event.getHand().equals(EquipmentSlot.OFF_HAND)) return;

    if(
            event.getAction().equals(Action.RIGHT_CLICK_AIR) ||
            event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
        on(player, Spell.MouseClick.RIGHT);
    }
}
项目:Kineticraft    文件:ArmorStands.java   
public ArmorPose(ArmorStand a) {
    this(a.getHeadPose(), a.getBodyPose(), a.getLeftArmPose(), a.getRightArmPose(), a.getLeftLegPose(), a.getRightLegPose(), new JsonMap<>());
    for (EquipmentSlot slot : EquipmentSlot.values()) { // Save gear.
        ItemStack i = Utils.getItem(a, slot);
        if (!Utils.isAir(i))
            getGear().put(slot.name(), i);
    }
}
项目:MT_Core    文件:GeneratorListener.java   
@EventHandler
public void onInteractBusy(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null)
        return;
    if (!inUse.contains(event.getClickedBlock().getLocation()))
        return;

    event.setCancelled(true);

    if (event.getHand() == EquipmentSlot.HAND)
        event.getPlayer().sendMessage(ChatColor.RED + "That generator is busy right now!");
}
项目:MT_Core    文件:GeckPowerListener.java   
@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!");
    }
}
项目:PA    文件:SpawnMob.java   
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSpawn(PlayerInteractEvent e){
    Player p = e.getPlayer();

    if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(e.getHand() != EquipmentSlot.HAND) return;
        if (e.getItem() == null || !e.getItem().hasItemMeta() || !e.getItem().getItemMeta().hasDisplayName() || e.getItem().getType() != Material.MONSTER_EGG) return;
        if (!ChatColor.stripColor(e.getItem().getItemMeta().getDisplayName()).contains("Spawn")) return;
        int id = Integer.parseInt(e.getItem().getItemMeta().getLore().get(0));
        String s = e.getItem().getItemMeta().getLore().get(1);

        boolean canCatch = true;
        ApplicableRegionSet region = plugin.getWg().getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation());
        for (ProtectedRegion r : region.getRegions()) if (!r.getOwners().contains(p.getName())) canCatch = false;

        if (!canCatch) {
            p.sendMessage(SafariNet.getInstance().getPrefix() + ChatColor.RED + "No puedes spawnear un mob en parcelas ajenas");
            return;
        }

        SNMob mob = new SNMob(p);
        if (!mob.isOwner(id)) {
           p.sendMessage(SafariNet.getInstance().getPrefix() + ChatColor.RED + "No eres el dueño de este huevo");
            return;
        }
        mob.spawnMob(id, s);
        p.getInventory().getItemInMainHand().setAmount(-1);
    }
}
项目:AsgardAscension    文件:RuneListener.java   
@EventHandler
public void onRuneUse(PlayerInteractEvent event) {
    if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
        return;
    }

    if(event.getHand() == null || !event.getHand().equals(EquipmentSlot.HAND)) {
        return;
    }

    ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
    if(item == null || item.getItemMeta() == null || !item.getType().equals(Material.ENCHANTED_BOOK)) {
        return;
    }

    Player player = event.getPlayer();
    Rune rune = plugin.getRuneManager().getRune(item.getItemMeta().getDisplayName().substring(2));
    if(rune == null) {
        return;
    }

    event.setCancelled(true);

    if(plugin.getRuneManager().hasActiveRune(player)) {
        player.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_RUNE_ALREADY_ACTIVE.toString());
        return;
    }

    if(Cooldowns.getCooldown(player, "rune") > 0) {
        player.sendMessage(Lang.HEADERS_TOKENS.toString() + Lang.TOKENS_RUNE_COOLDOWN.toString()
            .replaceAll("%d", Convert.timeToString((int) (Cooldowns.getCooldown(player, "rune") / 1000))));
        return;
    }

    plugin.getRuneManager().start(player, rune);
}
项目:MundoSK    文件:ArmorStandEquipmentSlot.java   
public static EquipSlot getByEquipmentSlot(EquipmentSlot equipmentSlot) {
    switch (equipmentSlot) {
        case HEAD: return HELMET;
        case CHEST: return CHESTPLATE;
        case LEGS: return LEGGINGS;
        case FEET: return BOOTS;
        default: return TOOL;
    }
}
项目:CastleGates    文件:BridgeEventHandler.java   
public boolean handleBlockClicked(PlayerInteractEvent event, PlayerStateManager.PlayerState state) {
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getHand() == EquipmentSlot.HAND) {
        simpleActivate(event);
        return false;
    }

    if(event.getAction() != Action.LEFT_CLICK_BLOCK) return false;

    boolean interacted = false;
    ConfigManager configManager = CastleGates.getConfigManager();
    CommandMode mode = state != null ? state.mode: CommandMode.OFF;

    if(configManager.getAllowAutoCreate() && configManager.isCreationConsumeItem(event.getItem())) {
        interacted = createGearblockAndLink(event);
    }
    else if(mode == CommandMode.INFO) {
        showGearInfo(event);
        interacted = true;
    }
    else if(mode == CommandMode.TIMER) {
        interacted = setGearblockTimer(event, state);
    }
    else if(configManager.isStickItem(event.getItem())) {
        switch(mode) {
            case CREATE:
                interacted = createGearblock(event);
                break;
            case LINK:
                interacted = linkGearblocks(event);
                break;
            default:
                interacted = false;
                break;
        }
    }

    return interacted;
}
项目:GamePlate    文件:InventoryViewModule.java   
@EventHandler(ignoreCancelled = true)
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (ObserverModule.isObserver(event.getPlayer())) {
        if (event.getRightClicked() instanceof Player && !event.getPlayer().isSneaking()){
            if (event.getHand().equals(EquipmentSlot.HAND)) {
                openInventory(event.getPlayer(), (Player) event.getRightClicked(), false);
            }
        }
    }
}
项目:Damocles    文件:EventCanceller.java   
@EventHandler
public void runeCreation(PlayerInteractEntityEvent event){
    if(event.getRightClicked() instanceof EnderCrystal){
        event.setCancelled(true);
        if(event.getHand().equals(EquipmentSlot.OFF_HAND))
            return;

        event.getRightClicked().remove();
        Player player = event.getPlayer();
        int rand = ThreadLocalRandom.current().nextInt(100);
        if(rand <= 50){
            World world = event.getRightClicked().getWorld();
            Location loc = event.getRightClicked().getLocation();
            world.createExplosion(loc.getX(), loc.getY(), loc.getZ(), 2, false, false);
            Message.sendCenteredMessage(player, ChatColor.GREEN+"----------------------------------------------------");
            Message.sendCenteredMessage(player, ChatColor.BOLD + "Rune");
            Message.sendCenteredMessage(player, ChatColor.YELLOW + "You fail to harvest any runes.");
            Message.sendCenteredMessage(player, ChatColor.GREEN+"----------------------------------------------------");
            return;
        }else{
            Enchantments[] enchants = Enchantments.values();
            Enchantments ench = enchants[ThreadLocalRandom.current().nextInt(enchants.length - 1)];
            int level = ThreadLocalRandom.current().nextInt(enchantclass.getMaxLevel(ench) + 1);
            if(level == 0)
                level = 1;
            event.getRightClicked().getWorld().dropItem(event.getRightClicked().getLocation(), new ca.damocles.itemblueprints.Rune(ench, level, ThreadLocalRandom.current().nextInt(100), ThreadLocalRandom.current().nextInt(100)).getItemStack());
            Message.sendCenteredMessage(player, ChatColor.GREEN+"----------------------------------------------------");
            Message.sendCenteredMessage(player, ChatColor.BOLD + "Rune");
            Message.sendCenteredMessage(player, ChatColor.YELLOW + "You successefuly harvest some runes.");
            Message.sendCenteredMessage(player, ChatColor.GREEN+"----------------------------------------------------");
            return;
        }
    }
    return;
}