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


Java PlayerInteractEvent.setUseItemInHand方法代碼示例

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


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

示例1: handleUse

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
private void handleUse(Event event, BlockState blockState, MatchPlayer player) {
    if(!player.canInteract()) return;

    PlayerBlockEventQuery query = new PlayerBlockEventQuery(player, event, blockState);

    for(EventRule rule : this.ruleContext.get(EventRuleScope.USE)) {
        if(rule.region().contains(blockState)) {
            if(processQuery(rule, query)) {
                if(query.getEvent() instanceof PlayerInteractEvent && ((PlayerInteractEvent) query.getEvent()).isCancelled()) {
                    PlayerInteractEvent pie = (PlayerInteractEvent) query.getEvent();
                    pie.setCancelled(false);
                    pie.setUseItemInHand(Event.Result.ALLOW);
                    pie.setUseInteractedBlock(Event.Result.DENY);

                    if(rule.message() != null) {
                        player.sendWarning(rule.message(), false);
                    }
                }
                if(this.useRegionPriority) {
                    break;
                }
            }
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:26,代碼來源:EventRuleMatchModule.java

示例2: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent event) {
    if(cancelUnlessInteracting(event, event.getPlayer())) {
        // Allow the how-to book to be read
        if(event.getMaterial() == Material.WRITTEN_BOOK) {
            event.setUseItemInHand(Event.Result.ALLOW);
        } else {
            event.setUseItemInHand(Event.Result.DENY);
            event.setUseInteractedBlock(Event.Result.DENY);
        }

        MatchPlayer player = getMatch().getPlayer(event.getPlayer());
        if(player == null) return;

        if(!player.isSpawned()) {
            ClickType clickType = convertClick(event.getAction(), event.getPlayer());
            if(clickType == null) return;

            getMatch().callEvent(new ObserverInteractEvent(player, clickType, event.getClickedBlock(), null, event.getItem()));
        }

        // Right-clicking armor will put it on unless we do this
        event.getPlayer().updateInventory();
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:26,代碼來源:EventFilterMatchModule.java

示例3: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOW)
public void onInteract(PlayerInteractEvent event) {
    if(!event.hasItem()) return;

    final ClickType click;
    switch(event.getAction()) {
        case LEFT_CLICK_AIR:
        case LEFT_CLICK_BLOCK:
            click = ClickType.LEFT;
            break;

        case RIGHT_CLICK_AIR:
        case RIGHT_CLICK_BLOCK:
            click = ClickType.RIGHT;
            break;

        default:
            return;
    }

    if(onButtonClick(event.getItem(), event.getActor(), click, event)) {
        event.setUseItemInHand(Event.Result.DENY);
        event.setUseInteractedBlock(Event.Result.DENY);
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:26,代碼來源:ButtonManager.java

示例4: interactEntity

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGH)
public void interactEntity(PlayerInteractEvent event) {
    if(!event.getPlayer().isOp()) {
        event.setCancelled(true);
        event.setUseInteractedBlock(Event.Result.DENY);
        event.setUseItemInHand(Event.Result.DENY);
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:9,代碼來源:EnvironmentControlListener.java

示例5: onThrowTNT

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onThrowTNT(PlayerInteractEvent event) {
	Player p = event.getPlayer();
	Gamer g = Gamer.get(p.getName());
	if (g.getVariable("spectator") != null)
		return;

	if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
		if (p.getItemInHand().getType() == Material.TNT) {
			// Frag Grenades
			TNTPrimed e = (TNTPrimed) event.getPlayer().getWorld().spawnEntity(p.getEyeLocation(),	EntityType.PRIMED_TNT);
			e.setFuseTicks(38);
			e.setYield(2.5F);
			e.setVelocity(event.getPlayer().getEyeLocation().getDirection());
			e.setMetadata("Player", new FixedMetadataValue(Nexus.getPlugin(), g.getPlayer().getName()));
			e.setMetadata("Cause", new FixedMetadataValue(Nexus.getPlugin(), CustomDamageCause.TNT_GRENADE.name()));
			
			event.setUseItemInHand(Event.Result.DENY);
			ItemStack stack = null;
			if (event.getItem().getAmount() > 1) {
				ItemStack s = event.getItem();
				s.setAmount(event.getItem().getAmount() - 1);
				stack = s;
			}
			p.getInventory().setItem(p.getInventory().getHeldItemSlot(), stack);
			event.setCancelled(true);
		}
	}
}
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:30,代碼來源:KitEvents.java


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