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


Java PlayerInteractEvent.setCancelled方法代碼示例

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


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

示例1: onUseBackpack

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST)
public void onUseBackpack(PlayerInteractEvent event) {
    ItemStack item = event.getItem();
    if (!event.hasItem() || !ItemUtils.hasTag(item, ItemUtils.BACKPACK_TAG)) {
        return;
    }

    Player player = event.getPlayer();
    Action action = event.getAction();
    if ((action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)
            && InventoryManager.isQuickSlot(player.getInventory().getHeldItemSlot())) {
        BackpackManager.open(player, item);
    }

    event.setCancelled(true);
    player.updateInventory();
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:19,代碼來源:BackpackListener.java

示例2: onSpectatorInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onSpectatorInteract(PlayerInteractEvent event) {
	Player p = event.getPlayer();
	Gamer g = Gamer.get(p.getName());
	if (!g.isInvisible())
		return;
	
	if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.PHYSICAL) {
		event.setCancelled(true);
		return;
	}
	
	
	int cur = 0;
	if (g.getVariable("spectating") != null)
		cur = (Integer) g.getVariable("spectating");
	int next = cur + 1;
	if (next + 1 >= Game.getTributes().size())
		next = 0;
	g.setVariable("spectating", next);
	Gamer t = Game.getTributes().get(next);
	g.getPlayer().teleport(t.getPlayer().getLocation());
	Chat.player(g.getPlayer(), "&2[SG] &eCurrently spectating " + g.getPrefix() + g.getName());
	event.setCancelled(true);
}
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:26,代碼來源:Events.java

示例3: onInteract

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

    Block target = evt.getPlayer().getTargetBlock((Set<Material>) null, 50);
    if (target.getZ() != ARENA_Z || target.getX() < MIN_X || target.getX() > MAX_X)
        return; // Not clicking on the canvas.

    if (target.getY() > MAX_Y && target.getY() <= MAX_Y + 5) { // Pick color.
        penTime = 0;
        currentColor = target.getData();
        updateActionBar();
        currentPainter.playSound(currentPainter.getLocation(), Sound.BLOCK_BREWING_STAND_BREW, 0.75F, 1.75F);
    } else if (evt.getAction() == Action.RIGHT_CLICK_AIR) { // Pen Tool
        penTime = System.currentTimeMillis() + 200;
        placeInk();
        evt.setCancelled(true); // Prevent "cl
    } else if (evt.getAction() == Action.LEFT_CLICK_AIR) { // Fill
        playSound(Sound.ENTITY_BOBBER_SPLASH, 1.5F, 0.5F);
        floodFill(target);
    }
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:24,代碼來源:Pictionary.java

示例4: onClick

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onClick(PlayerInteractEvent e) {
	Action act = e.getAction();
	if (!(act.equals(Action.RIGHT_CLICK_AIR) || act.equals(Action.RIGHT_CLICK_BLOCK)))
		return;
	ItemStack item = e.getItem();
	if (item == null)
		return;
	if (!item.hasItemMeta())
		return;
	if (!item.getItemMeta().hasDisplayName())
		return;
	if (!item.getItemMeta().getDisplayName().contains(ConfigManager.getInstance().getBackpackName()))
		return;
	Player p = e.getPlayer();
	String name = p.getName();
	if (BackpackCooldown.getInstance().isReady(name, 500)) {
		BackpackCooldown.getInstance().put(name);
	} else {
		e.setCancelled(true);
		p.closeInventory();
		p.sendMessage(Messages.getMessages().getNoQuickOpen().replace("&", "§"));
	}
}
 
開發者ID:Soldier233,項目名稱:SlimefunBugFixer,代碼行數:25,代碼來源:Listeners.java

示例5: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
        // The player didn't click an enchantment table, Creative players will instantly destroy.
        Player player = event.getPlayer();
        if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {

            // The player didn't click with an enchanted book.
            ItemStack stack = event.getItem();
            if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
                ItemMeta meta = stack.getItemMeta();
                if (meta instanceof EnchantmentStorageMeta) {
                    EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
                    for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
                        enchantmentStorageMeta.removeStoredEnchant(enchantment);
                    }

                    event.setCancelled(true);
                    player.setItemInHand(EMPTY_BOOK);
                    player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
                }
            }
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:BookDeenchantListener.java

示例6: 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

示例7: onPlayerInteractWhenNotLoaded

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteractWhenNotLoaded(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    if (InventoryManager.isAllowedWorld(player.getWorld()) && !InventoryManager.playerIsLoaded(player)) {
        PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.rp.denied"));
        event.setCancelled(true);
    }
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:10,代碼來源:PlayerListener.java

示例8: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onInteract(final PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) return;

    ItemStack item = event.getItem();
    if (item instanceof PlayerheadItemStack) {
        event.setCancelled(true);
        Player player = event.getPlayer();

        //Use the item
        if (item.getAmount() > 1) item.setAmount(item.getAmount() - 1);
        else player.getInventory().remove(item);

        MainConfiguration config = UHC.getInstance().getMainConfig();

        //Give effects & crap
        PlayerheadItemStack playerhead = (PlayerheadItemStack) item;
        boolean golden = playerhead.isGolden();
        player.sendMessage(colour("&aYou ate " + playerhead.getFrom() + "'s playerhead!"));

        int regenDuration = golden ? config.getGoldenHeadRegenerationDuration() : config.getHeadRegenerationDuration();
        int regenAmpf = golden ? config.getGoldenHeadRegenerationAmplifier() : config.getHeadRegenerationAmplifier();
        int absorpDuration = golden ? config.getGoldenHeadAbsorptionDuration() : config.getHeadAbsorptionDuration();
        int absorpAmpf = golden ? config.getGoldenHeadAbsorptionAmplifier() : config.getHeadAbsorptionAmplifier();

        player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, regenDuration, regenAmpf, false, true));
        player.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, absorpDuration, absorpAmpf, false, true));
    }
}
 
開發者ID:Project-Coalesce,項目名稱:UHC,代碼行數:30,代碼來源:HeadEatHandler.java

示例9: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e)
{
    User user = MWAPI.getUserHandler().findById(e.getPlayer().getUniqueId());

    if (user.getGame() != null)
    {
        Game game = user.getGame();

        if (game.getState() == GameState.LOBBY && game.isPlaying(user))
        {
            e.setCancelled(true);
            e.getPlayer().updateInventory();

            if (e.getPlayer().getItemInHand().getType().equals(Material.CHEST))
            {
                e.getPlayer().sendMessage(ChatColor.RED + "Coming Soon.");
            }
            else if (e.getPlayer().getItemInHand().getType().equals(Material.WOOL))
            {
                e.getPlayer().sendMessage(ChatColor.RED + "Coming Soon.");
            }
            else if (e.getPlayer().getItemInHand().getType().equals(Material.BED))
            {
                boolean success = game.leave(user);

                if (success)
                {
                    user.getPlayer().sendMessage(ChatColor.GOLD + "Successfully left game " + game.getId() + ".");
                }
                else
                {
                    user.getPlayer().sendMessage(ChatColor.RED + "Error while leaving game " + game.getId() + ".");
                }
            }
        }
    }
}
 
開發者ID:WoutDev,項目名稱:Mega-Walls,代碼行數:39,代碼來源:PlayerInteractListener.java

示例10: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onInteract(PlayerInteractEvent e) {
    final TOAUser u = TOA.getPlayer(e.getPlayer());

    if (e.getItem() != null) {
        Material m = e.getItem().getType();
        if (m == Material.WRITTEN_BOOK || m == Material.BOW || m == Material.SHEARS || m == Material.DIAMOND_SWORD) return;
        Ability.useAbility(u, e.getItem().getType());
        e.setCancelled(true);
    }

    if (!u.isOnRank(PACmd.Grupo.Builder)) {
        if (e.getClickedBlock() != null) {
            if (e.getClickedBlock().getType().equals(Material.TRAP_DOOR) || e.getClickedBlock().getType().equals(Material.IRON_TRAPDOOR)
                    || e.getClickedBlock().getType().equals(Material.FENCE_GATE) || e.getClickedBlock().getType().equals(Material.FIRE)
                    || e.getClickedBlock().getType().equals(Material.CAULDRON) || e.getClickedBlock().getRelative(BlockFace.UP).getType().equals(Material.FIRE)
                    || e.getClickedBlock().getType() == Material.CHEST || e.getClickedBlock().getType() == Material.TRAPPED_CHEST
                    || e.getClickedBlock().getType() == Material.DROPPER || e.getClickedBlock().getType() == Material.DISPENSER
                    || e.getClickedBlock().getType() == Material.BED_BLOCK || e.getClickedBlock().getType() == Material.BED
                    || e.getClickedBlock().getType() == Material.WORKBENCH || e.getClickedBlock().getType() == Material.BREWING_STAND
                    || e.getClickedBlock().getType() == Material.ANVIL || e.getClickedBlock().getType() == Material.DARK_OAK_FENCE_GATE
                    || e.getClickedBlock().getType() == Material.SPRUCE_FENCE_GATE || e.getClickedBlock().getType() == Material.FURNACE
                    || e.getClickedBlock().getType() == Material.BURNING_FURNACE || e.getClickedBlock().getType() == Material.HOPPER
                    || e.getClickedBlock().getType() == Material.STONE_BUTTON || e.getClickedBlock().getType() == Material.WOOD_BUTTON) {
                e.setCancelled(true);
            }
        }
    }
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:30,代碼來源:GameEvents.java

示例11: onFoodEat

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler
public void onFoodEat(PlayerInteractEvent event) {
	if(!(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
		return;
	}
	if(!event.getPlayer().isSneaking() || event.getPlayer().getInventory().getItemInMainHand() == null) {
		return;
	}
	
	Player player = event.getPlayer();
	List<Integer> ids = GodFoodFile.getFoodId(player.getInventory().getItemInMainHand().getTypeId());
	for(int id : ids) {
		byte data = (byte)GodFoodFile.getData(id);
		
		if(player.getInventory().getItemInMainHand().getData().getData() != data || id == 0)
			continue;
		
		if(player.getInventory().getItemInMainHand().getAmount() > GodFoodFile.getAmount(id)) {
			ItemStack item = player.getInventory().getItemInMainHand();
			item.setAmount(item.getAmount() - GodFoodFile.getAmount(id));
			player.setItemInHand(item);
		} else if(player.getInventory().getItemInMainHand().getAmount() == GodFoodFile.getAmount(id)) {
			player.setItemInHand(new ItemStack(Material.AIR));
		} else {
			return;
		}
		event.setCancelled(true);
		
		addPotionEffects(player, id);
		player.sendMessage(Lang.HEADERS_FOG.toString() + "You used " 
				+ ChatColor.RED + GodFoodFile.getName(id) + ChatColor.GRAY + "!");
	}
}
 
開發者ID:benNek,項目名稱:AsgardAscension,代碼行數:35,代碼來源:GodFoodListener.java

示例12: onAnvilOrEnchantInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onAnvilOrEnchantInteract(PlayerInteractEvent event) {
    if (event.getClickedBlock() != null) {
        if (event.getPlayer().getGameMode() == GameMode.CREATIVE && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK))
            return;
        Material type = event.getClickedBlock().getType();
        for (Material m : RESTRICTED_TYPES) {
            if (m == type) {
                event.setCancelled(true);
                break;
            }
        }
    }
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:15,代碼來源:EnvironmentManager.java

示例13: anvilStuff

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler
public void anvilStuff(PlayerInteractEvent e){
	if(e.getClickedBlock() == null)return;
	if(e.getClickedBlock().getType().equals(Material.ANVIL)){
		e.setCancelled(true);
		Player p = e.getPlayer();
		String uuid = p.getUniqueId().toString();
		long tokens = getTokens(uuid);
		if(p.getItemInHand().getType() == Material.AIR ||
				p.getItemInHand().getType() == Material.GOLDEN_APPLE ||
				p.getItemInHand().getType() == Material.ARROW ||
				p.getItemInHand().getType() == Material.POTION){
			
			p.sendMessage(tag + ChatColor.RED + "You can\'t repair that!");
		}else{
			if(tokens < 1){
				p.sendMessage(tag + ChatColor.RED + "You need at least 1 token to repair things!!");
			}else{
				if(p.getItemInHand().getDurability() > 0){
					p.getItemInHand().setDurability((short) 0);
					setTokens(uuid, getTokens(uuid)-1);
					p.sendMessage(tag + ChatColor.BLUE + "Your item has been repaired");
				}else{
					p.sendMessage(tag + ChatColor.RED + "This item isn\'t broken");
				}
			}
		}
	}
}
 
開發者ID:OverloadedCore,項目名稱:kaosEssentials,代碼行數:31,代碼來源:Core.java

示例14: InteractCheck

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
@SuppressWarnings("deprecation")
public void InteractCheck(PlayerInteractEvent event) {
    if (ConfigPatch.noInfItem) {
        Player player = event.getPlayer();
        if (event.getItem() != null) {
            if (event.getItem().getAmount() <= 0) {
                event.setCancelled(true);
                player.setItemInHand(null);
                AzureAPI.log(player, ConfigPatch.AntiInfItemClickcWarnMessage);
            }
        }
    }
}
 
開發者ID:GelandiAssociation,項目名稱:EscapeLag,代碼行數:15,代碼來源:AntiInfItem.java

示例15: cloneCraftingWindow

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR)
public void cloneCraftingWindow(final PlayerInteractEvent event) {
    if(!AntiGrief.CraftProtect.enabled()) {
        return;
    }

    if(!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) {
        Block block = event.getClickedBlock();
        if(block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) {
            // create the window ourself
            event.setCancelled(true);
            event.getPlayer().openWorkbench(null, true); // doesn't check reachable
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:16,代碼來源:CraftingProtect.java


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