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


Java PlayerInteractEvent.isCancelled方法代碼示例

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


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

示例1: onConsumeCake

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsumeCake(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.hasBlock() && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
	{
		Block cake = event.getClickedBlock();
		if(cake.getType().equals(Material.CAKE_BLOCK))
		{
			if(player.getFoodLevel() < 20 && (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE))
			{
				addStats(player, carbon, 171);
				addStats(player, protein, 114);
				addStats(player, salts, 3);
			}
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:20,代碼來源:FoodDiversityConsume.java

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

示例3: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
public void onPlayerInteract(PlayerInteractEvent e) {
	if (e.isCancelled()) return;
     KingdomFactionsPlayer p = PlayerModule.getInstance().getPlayer(e.getPlayer());        
		if(p.getSettingsProfile().hasAdminMode()) return;
	if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
		if (e.getClickedBlock() == null) return;

		Block clickedBlock = e.getClickedBlock();
	

		if (clickedBlock.getType().equals(Material.CHEST) || clickedBlock.getType().equals(Material.TRAPPED_CHEST) || clickedBlock.getType().equals(Material.BEACON)) {
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 500));
			return;
		}

		if (clickedBlock.getType().equals(Material.BURNING_FURNACE) || clickedBlock.getType().equals(Material.FURNACE) || clickedBlock.getType().equals(Material.DISPENSER) || clickedBlock.getType().equals(Material.HOPPER) || clickedBlock.getType().equals(Material.DROPPER)) {
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 150));
			return;
		}

		MaterialData data = clickedBlock.getState() != null ? clickedBlock.getState().getData() : null;
		if (data instanceof Openable) {
			if (clickedBlock.getType() == Material.IRON_TRAPDOOR || clickedBlock.getType() == Material.IRON_DOOR) return;
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 150));
			return;
		}
	}
}
 
開發者ID:ThEWiZ76,項目名稱:KingdomFactions,代碼行數:29,代碼來源:PlayerInteractEventListener.java

示例4: soilChangePlayer

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void soilChangePlayer(PlayerInteractEvent e) {
      if(e.getClickedBlock() == null) return;
	if ((e.getAction() == Action.PHYSICAL) && (e.getClickedBlock().getType() == Material.SOIL)) {
		KingdomFactionsPlayer p = PlayerModule.getInstance().getPlayer(e.getPlayer());
		if(p.isVanished()) return;
		if(e.isCancelled()) return;
		if(!p.canBuild(e.getClickedBlock().getLocation())) {
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 50));
		} 

	}
	}
 
開發者ID:ThEWiZ76,項目名稱:KingdomFactions,代碼行數:14,代碼來源:BuildEventListener.java

示例5: onUse

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onUse(PlayerInteractEvent e) {

	try {
		if (e.getAction() != Action.LEFT_CLICK_BLOCK) {
			return;
		}
		if (e.getItem() == null) return;
		if (!e.getItem().hasItemMeta()) return;
		if (!e.getItem().getItemMeta().getDisplayName().equalsIgnoreCase(WreckingBallModule.WRECKINGBALL_NAME))
			return;
		if (e.isCancelled()) return;
		KingdomFactionsPlayer player = PlayerModule.getInstance().getPlayer(e.getPlayer());
		if (player.isVanished()) return;
		if (!player.isStaff()) {
			player.getInventory().setItem(player.getInventory().getHeldItemSlot(), null);
			player.sendMessage(Messages.getInstance().getPrefix() + "Het is voor jou niet toegestaan om dit item te gebruiken");
			return;
		}

		if (e.getClickedBlock() == null) return;
		if (e.isCancelled()) return;

		BlockWreckedEvent ev = new BlockWreckedEvent(e.getClickedBlock(), player.getPlayer());
		Bukkit.getPluginManager().callEvent(ev);

		e.getClickedBlock().breakNaturally();

	} catch (NullPointerException npe) {
		//bad practise!
	}

}
 
開發者ID:ThEWiZ76,項目名稱:KingdomFactions,代碼行數:34,代碼來源:WreckingBallListeners.java

示例6: onStep

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@GameEvent
public void onStep(@Nonnull PlayerInteractEvent event) {
    if (event.getAction() == Action.PHYSICAL) {
        if (event.getClickedBlock().getType() != Material.WOOD_PLATE && event.getClickedBlock().getType() != Material.STONE_PLATE) {
            return;
        }
        if (event.isCancelled()) {
            return;
        }
        double strength = 1.5;
        double up = 1;
        if (event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState() instanceof Sign) {
            Sign sign = (Sign) event.getClickedBlock().getRelative(BlockFace.DOWN, 2).getState();
            if (sign.getLine(0).contains("[Boom]")) {
                try {
                    strength = Double.parseDouble(sign.getLine(1));
                    up = Double.parseDouble(sign.getLine(2));
                } catch (final Exception ex) {
                    log.warning("Invalid boom sign at " + sign.getLocation());
                }
            }
        }

        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.ENTITY_ENDERDRAGON_SHOOT, 10.0F, 1.0F);
        event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 10);
        Vector v = event.getPlayer().getLocation().getDirection().multiply(strength / 2).setY(up / 2);
        event.getPlayer().setVelocity(v);
        event.setCancelled(true);
    }
}
 
開發者ID:VoxelGamesLib,項目名稱:VoxelGamesLibv2,代碼行數:31,代碼來源:JumpPadFeature.java

示例7: clickable

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void clickable(PlayerInteractEvent evt) {
    Action act = evt.getAction();
    if ((evt.isCancelled() && act != Action.LEFT_CLICK_AIR && act != Action.LEFT_CLICK_AIR) || evt.isAsynchronous()) return;
    
    ItemStack stack = evt.getItem();
    if (stack == null) return;
    ItemMeta meta = stack.getItemMeta();
    if (!meta.hasLore()) return;
    
    for (String lore : meta.getLore()) {
        Item item = ItemFactory.items.get(lore);
        if (item instanceof ClickableItem) {
            if (item instanceof LeftClickOnly) {
                if (act == Action.LEFT_CLICK_BLOCK || act == Action.LEFT_CLICK_AIR) {
                    ((ClickableItem) item).run(evt);
                }
                continue;
            }
            
            if (item instanceof RightClickOnly) {
                if (act == Action.RIGHT_CLICK_BLOCK || act == Action.RIGHT_CLICK_AIR) {
                    ((ClickableItem) item).run(evt);
                }
                continue;
            }
            
            // common type
            ((ClickableItem) item).run(evt);
        }
    }
}
 
開發者ID:Recraft,項目名稱:Recreator,代碼行數:33,代碼來源:ItemActionListener.java

示例8: call

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@Override
public void call(Event event) {
	if (event instanceof PlayerInteractEvent) {
		final PlayerInteractEvent pie = (PlayerInteractEvent) event;
		if (pie.getAction() != Action.LEFT_CLICK_AIR && pie.getAction() != Action.LEFT_CLICK_BLOCK
				&& !pie.isCancelled()) {
			return;
		}
	} else if (!(event instanceof EntityDamageByEntityEvent)) {
		return;
	}

	store.call();

	if (store.getCurrentClickRate() > SUSPICIOUS_CPS) {
		aboveSuspicious++;
		final double certainty = (aboveSuspicious / store.getTotalClicks()) * 100.0;
		if (certainty > 70.0) {
			/*
			 * If more than 70% of the clicks are deemed to be suspicious,
			 * the player is probably cheating.
			 */
			callback(true);
		}
	}

	final ArrayList<Double> clicks = store.getCPSInTime(REVIEW_TIME);

	if (clicks.size() < NEEDED_SAMPLES) {
		return;
	}
	// Check for oscillating autoclickers.

	// Every time we identify something suspicious, add to this.
	int chance = 0;

	ArrayList<Double> differences = new ArrayList<Double>();
	for (int i = 0; i < clicks.size(); i++) {
		if (i != 0) {
			final double current = clicks.get(i), previous = clicks.get(i - 1);

			if (previous < current) {
				chance++;
			}

			if (i % 1 == 0) {
				// Use absolute so we can identify if the
				// autoclicker
				// slows down too.
				final double difference = Math.abs(current - previous);

				if (differences.size() != 0) {
					// Compare this difference to previous
					// differences.
					for (int p = 0; p < differences.size(); p++) {
						final double differenceBetweenDifferences = Math.abs(difference - differences.get(p));
						if (differenceBetweenDifferences == 0.0
								|| differenceBetweenDifferences < ALLOWED_INTERVAL) {
							chance++;
						}
					}
				}

				differences.add(difference);
			}
		}
	}

	final Double[] sorted = clicks.toArray(new Double[clicks.size()]);

	final double smallest = sorted[0], largest = sorted[sorted.length - 1];

	if (largest - smallest == 0.0) {
		chance += sorted.length;
	}

	Bukkit.broadcastMessage("autoclicker chance: " + chance);
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:79,代碼來源:AutoclickerA.java

示例9: onInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler
public void onInteract(PlayerInteractEvent e) {
	KingdomFactionsPlayer p = PlayerModule.getInstance().getPlayer(e.getPlayer());
	if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
	if(p.hasBuildAction()) e.setCancelled(true);
	if(p.isVanished()) return;
	if(e.isCancelled()) return;
	if(e.getClickedBlock() == null) return;
	if(!p.canBuild(e.getClickedBlock().getLocation())) {
		switch(e.getClickedBlock().getType()) {
		case CHEST:
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 300));
			break;
		case TRAPPED_CHEST:
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 300));
			break;
		case ENDER_CHEST:
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 200));
			break;
		case ACACIA_DOOR:
		case BIRCH_DOOR:
		case DARK_OAK_DOOR:
		case SPRUCE_DOOR:
		case JUNGLE_DOOR:
		case WOODEN_DOOR:
		case TRAP_DOOR:
		case IRON_DOOR:
		case IRON_TRAPDOOR:
		case SPRUCE_FENCE_GATE:
		case DARK_OAK_FENCE_GATE:
		case BIRCH_FENCE_GATE:
		case FENCE_GATE:
		case ACACIA_FENCE_GATE:
		case JUNGLE_FENCE_GATE:
		case DISPENSER:
		case DROPPER:
		case FURNACE:
		case HOPPER:
		case BURNING_FURNACE:
			e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 200));
		break;
			
	    default: break;
		}
	} 

}
 
開發者ID:ThEWiZ76,項目名稱:KingdomFactions,代碼行數:48,代碼來源:BuildEventListener.java

示例10: onItemClick

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemClick(PlayerInteractEvent event)
{
	if(event.isCancelled()) return;
	if(event.hasItem())
	{
		Player player = event.getPlayer();
		if(player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)
		{
			ItemStack mainItem = player.getInventory().getItemInMainHand();
			if(mainItem.getType() == Material.GLASS_BOTTLE)
			{
				if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
				{
					if(event.getClickedBlock().getType() == Material.CAULDRON && event.getClickedBlock().getData() != (byte)0)
					{
						Block fire = event.getClickedBlock().getRelative(BlockFace.DOWN);
						event.setCancelled(true);
						
						event.getClickedBlock().setData((byte)((int)event.getClickedBlock().getData() - 1));
						
						ItemStack waterBottle = new ItemStack(Material.POTION, 1);
						
						net.minecraft.server.v1_12_R1.ItemStack nmsStack_bottle = CraftItemStack.asNMSCopy(waterBottle);
				        NBTTagCompound compound_bottle = nmsStack_bottle.getTag();
				        compound_bottle.setString("Potion","minecraft:water");
				        compound_bottle.setInt("HideFlags", 32);
				        nmsStack_bottle.setTag(compound_bottle);
				        waterBottle = CraftItemStack.asBukkitCopy(nmsStack_bottle);
				        
						ItemMeta meta = waterBottle.getItemMeta();

						if(fire != null && fire.getType() == Material.FIRE)
						{
							List<String> lore = Arrays.asList
							(
								ChatColor.RESET + "" + ChatColor.GRAY + Survival.Words.get("Purified")
							);
							meta.setLore(lore);
						}
						waterBottle.setItemMeta(meta);
						
						if(mainItem.getAmount() > 1)
						{
							mainItem.setAmount(mainItem.getAmount() - 1);
							if(player.getInventory().firstEmpty() != -1)
								player.getInventory().addItem(waterBottle);
							else
								player.getWorld().dropItem(player.getLocation(), waterBottle);
						}
						else
						{
							player.getInventory().setItemInMainHand(waterBottle);
						}
					}
				}
			}
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:62,代碼來源:CauldronWaterBottle.java

示例11: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent e)
{
	if(e.isCancelled()) return;
	final Player p = e.getPlayer();
	
	if(e.getClickedBlock() == null)
		return;
	
	final Block block = e.getClickedBlock();
	
	if(e.getAction() != Action.RIGHT_CLICK_BLOCK)
		return;
	
	if(block.getType() == Material.WORKBENCH)
	{
		Bukkit.getServer().getScheduler().runTask(Survival.instance, new Runnable()
		{
			@Override
			public void run()
			{
				if (!p.isOnline())
					return;
				
				if (!block.hasMetadata("shared_players"))
					block.setMetadata("shared_players", new FixedMetadataValue(Survival.instance, new ArrayList<UUID>()));
				
				@SuppressWarnings("unchecked")
				final List<UUID> list = (block.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>) block.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>();
				
				final Inventory open = p.getOpenInventory().getTopInventory();
				
				if (open == null || open.getType() != InventoryType.WORKBENCH)
					return;

				// Workaround to get the accessed WorkBench
				final Block workbench = p.getTargetBlock((Set<Material>) null, 8);
				
				if (workbench == null || workbench.getType() != Material.WORKBENCH)
				{
					// Close Inventory if player managed to access the workbench without actually use one.
					p.closeInventory();
					return;
				}

				list.add(p.getUniqueId());
				p.setMetadata("shared_workbench", new FixedMetadataValue(Survival.instance, block));

				Bukkit.getServer().getScheduler().runTaskLater(Survival.instance, new Runnable()
				{
					@Override
					public void run()
					{
						if (list.isEmpty())
							return;
						Player first = Bukkit.getPlayer(list.get(0));
						Inventory pInv = first.getOpenInventory().getTopInventory();
						if (pInv == null || pInv.getType() != InventoryType.WORKBENCH)
							return;
						open.setContents(pInv.getContents());
						Bukkit.getServer().getScheduler().runTaskLater(Survival.instance, new Runnable()
						{
							@SuppressWarnings("deprecation")
							@Override
							public void run()
							{
								p.updateInventory();
							}
						}, 1);
					}
				}, 1);
			}
		});
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:76,代碼來源:WorkbenchShare.java

示例12: onPlayerInteract

import org.bukkit.event.player.PlayerInteractEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    Action action = event.getAction();
    if (event.hasItem() && (action == Action.RIGHT_CLICK_AIR || (action == Action.RIGHT_CLICK_BLOCK && !event.isCancelled()))) {
        ItemStack stack = event.getItem();
        if (!isBottledExperience(stack)) {
            return;
        }

        ItemMeta meta = stack.getItemMeta();
        List<String> lore = meta.getLore();

        Integer amount = null;
        for (String loreLine : lore) {
            if ((amount = JavaUtils.tryParseInt(ChatColor.stripColor(loreLine).split(" ")[0])) != null) {
                break;
            }
        }

        if (amount != null) {
            event.setCancelled(true);

            Player player = event.getPlayer();
            int previousLevel = player.getLevel();
            new ExperienceManager(player).changeExp(amount);

            // Play a fancy sound if they earned 5 exp levels.
            if ((player.getLevel() - previousLevel) > 5) {
                player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1.0F, 1.0F);
            }

            // If the hand is more than 1, decrease by 1
            // otherwise remove. To prevent user error.
            if (stack.getAmount() > 1) {
                stack.setAmount(stack.getAmount() - 1);
            } else {
                player.setItemInHand(new ItemStack(Material.GLASS_BOTTLE, 1));
            }
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:42,代碼來源:BottledExpListener.java


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