當前位置: 首頁>>代碼示例>>Java>>正文


Java EquipmentSlot類代碼示例

本文整理匯總了Java中org.bukkit.inventory.EquipmentSlot的典型用法代碼示例。如果您正苦於以下問題:Java EquipmentSlot類的具體用法?Java EquipmentSlot怎麽用?Java EquipmentSlot使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EquipmentSlot類屬於org.bukkit.inventory包,在下文中一共展示了EquipmentSlot類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onWalkieTalkieInteract

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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());
		}
	}

}
 
開發者ID:kadeska,項目名稱:MT_Communication,代碼行數:21,代碼來源:WalkieTalkieListener.java

示例2: onPlayerInteract

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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);
            }
        }
    }
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:18,代碼來源:ItemManager.java

示例3: misfire

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:ProgrammerDan,項目名稱:AddGun,代碼行數:31,代碼來源:StandardGun.java

示例4: onInteract

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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);
}
 
開發者ID:benfah,項目名稱:Bags2,代碼行數:20,代碼來源:BagEnchant.java

示例5: onInteract

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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);
	}
 
開發者ID:benfah,項目名稱:Bags2,代碼行數:18,代碼來源:BagStorage.java

示例6: onInteract

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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);
}
 
開發者ID:benfah,項目名稱:Bags2,代碼行數:22,代碼來源:BagBase.java

示例7: placeBlock

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
/**
 * "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;
}
 
開發者ID:RoboTricker,項目名稱:Transport-Pipes,代碼行數:28,代碼來源:HitboxUtils.java

示例8: listener

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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);
            }
        }
    };
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:19,代碼來源:ClickWizard.java

示例9: init

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
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);
}
 
開發者ID:EntryPointKR,項目名稱:MCLibrary,代碼行數:25,代碼來源:LibraryCommand.java

示例10: onClickEndPortalFrame

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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);
}
 
開發者ID:2008Choco,項目名稱:DragonEggDrop,代碼行數:22,代碼來源:PortalClickListener.java

示例11: getEquipmentSlot

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
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;
}
 
開發者ID:CardinalDevelopment,項目名稱:Cardinal,代碼行數:21,代碼來源:DocumentItems.java

示例12: onInteract

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
@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.");
            }
        }
    }
}
 
開發者ID:Explodncheez,項目名稱:MysteryBags,代碼行數:25,代碼來源:MysteryBagsListener.java

示例13: canEdit

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
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;
}
 
開發者ID:RypoFalem,項目名稱:ArmorStandEditor,代碼行數:24,代碼來源:PlayerEditorManager.java

示例14: allowedByBlockPlaceEvent

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
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;
}
 
開發者ID:rutgerkok,項目名稱:BlockLocker,代碼行數:17,代碼來源:InteractListener.java

示例15: blockPlacePretend

import org.bukkit.inventory.EquipmentSlot; //導入依賴的package包/類
/**
    * 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;
   }
 
開發者ID:StarQuestMinecraft,項目名稱:StarQuestCode,代碼行數:39,代碼來源:EventSimulator.java


注:本文中的org.bukkit.inventory.EquipmentSlot類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。