java类org.bukkit.inventory.EquipmentSlot的实例源码

WalkieTalkieListener.java 文件源码 项目:MT_Communication 阅读 19 收藏 0 点赞 0 评论 0
@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());
        }
    }

}
WalkieTalkieListener.java 文件源码 项目:MT_Communication 阅读 23 收藏 0 点赞 0 评论 0
@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());
        }
    }

}
ItemManager.java 文件源码 项目:ZentrelaRPG 阅读 27 收藏 0 点赞 0 评论 0
@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);
            }
        }
    }
}
StandardGun.java 文件源码 项目:AddGun 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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;
}
BagEnchant.java 文件源码 项目:Bags2 阅读 15 收藏 0 点赞 0 评论 0
@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);
}
BagStorage.java 文件源码 项目:Bags2 阅读 15 收藏 0 点赞 0 评论 0
@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);
    }
BagBase.java 文件源码 项目:Bags2 阅读 21 收藏 0 点赞 0 评论 0
@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);
}
HitboxUtils.java 文件源码 项目:Transport-Pipes 阅读 24 收藏 0 点赞 0 评论 0
/**
 * "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;
}
ClickWizard.java 文件源码 项目:MCLibrary 阅读 18 收藏 0 点赞 0 评论 0
@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);
            }
        }
    };
}
LibraryCommand.java 文件源码 项目:MCLibrary 阅读 18 收藏 0 点赞 0 评论 0
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);
}
PortalClickListener.java 文件源码 项目:DragonEggDrop 阅读 16 收藏 0 点赞 0 评论 0
@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);
}
DocumentItems.java 文件源码 项目:Cardinal 阅读 22 收藏 0 点赞 0 评论 0
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;
}
MysteryBagsListener.java 文件源码 项目:MysteryBags 阅读 21 收藏 0 点赞 0 评论 0
@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.");
            }
        }
    }
}
PlayerEditorManager.java 文件源码 项目:ArmorStandEditor 阅读 20 收藏 0 点赞 0 评论 0
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;
}
InteractListener.java 文件源码 项目:BlockLocker 阅读 21 收藏 0 点赞 0 评论 0
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;
}
EventSimulator.java 文件源码 项目:StarQuestCode 阅读 45 收藏 0 点赞 0 评论 0
/**
    * 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;
   }
QuestItemHandler.java 文件源码 项目:BetonQuest 阅读 24 收藏 0 点赞 0 评论 0
@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);
        }
    }
}
CraftEventFactory.java 文件源码 项目:SpigotSource 阅读 19 收藏 0 点赞 0 评论 0
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;
}
HotbarManager.java 文件源码 项目:uppercore 阅读 17 收藏 0 点赞 0 评论 0
@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
}
StandardGun.java 文件源码 项目:AddGun 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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;
}
PlayerEvent.java 文件源码 项目:WC 阅读 18 收藏 0 点赞 0 评论 0
@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);
        }
    }
}
SpawnMob.java 文件源码 项目:WC 阅读 15 收藏 0 点赞 0 评论 0
@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);
    }
}
Weapons.java 文件源码 项目:WC 阅读 20 收藏 0 点赞 0 评论 0
@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);
    }
}
BagEnder.java 文件源码 项目:Bags2 阅读 16 收藏 0 点赞 0 评论 0
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    if(hasPermission(ender_open, e.getPlayer()))
    {   
    e.getPlayer().openInventory(e.getPlayer().getEnderChest());
    }
    super.onInteract(e, es);
}
BagAnvil.java 文件源码 项目:Bags2 阅读 24 收藏 0 点赞 0 评论 0
@Override
public void onInteract(PlayerInteractEvent e, EquipmentSlot es)
{
    if(hasPermission(anvil_open, e.getPlayer()))
    {   
    Util.openAnvil(e.getPlayer());
    }
    super.onInteract(e, es);
}
BagCrafting.java 文件源码 项目:Bags2 阅读 19 收藏 0 点赞 0 评论 0
@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);
}
XMLUtils.java 文件源码 项目:ProjectAres 阅读 25 收藏 0 点赞 0 评论 0
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;
}
NMSHacks.java 文件源码 项目:ProjectAres 阅读 15 收藏 0 点赞 0 评论 0
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
    ));
}
SimpleWand.java 文件源码 项目:MystiCraft 阅读 19 收藏 0 点赞 0 评论 0
@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);
}
InputFormatterTest.java 文件源码 项目:Debuggery 阅读 27 收藏 0 点赞 0 评论 0
@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);
}


问题


面经


文章

微信
公众号

扫码关注公众号