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


Java PlayerInteractEvent.getHand方法代碼示例

本文整理匯總了Java中org.bukkit.event.player.PlayerInteractEvent.getHand方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInteractEvent.getHand方法的具體用法?Java PlayerInteractEvent.getHand怎麽用?Java PlayerInteractEvent.getHand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.event.player.PlayerInteractEvent的用法示例。


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

示例1: onWalkieTalkieInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的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.event.player.PlayerInteractEvent; //導入方法依賴的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: listener

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的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

示例4: onClickEndPortalFrame

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的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

示例5: onSpawn

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:cadox8,項目名稱:WC,代碼行數:34,代碼來源:SpawnMob.java

示例6: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:cadox8,項目名稱:WC,代碼行數:32,代碼來源:Weapons.java

示例7: onInteractBusy

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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!");
}
 
開發者ID:kadeska,項目名稱:MT_Core,代碼行數:13,代碼來源:GeneratorListener.java

示例8: onPlayerLeaverInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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!");
	}
}
 
開發者ID:kadeska,項目名稱:MT_Core,代碼行數:40,代碼來源:GeckPowerListener.java

示例9: onSpawn

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:30,代碼來源:SpawnMob.java

示例10: onRuneUse

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@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);
}
 
開發者ID:benNek,項目名稱:AsgardAscension,代碼行數:37,代碼來源:RuneListener.java

示例11: onBrewingClick

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的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);
}
 
開發者ID:ProtocolSupport,項目名稱:ProtocolSupportLegacySupport,代碼行數:42,代碼來源:BrewingStandFuelHandler.java


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