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


Java PlayerItemConsumeEvent類代碼示例

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


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

示例1: onPlayerItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{		
	for (String itemString : Thirst.getInstance().getYAMLConfig().thirstQuenchingItems)
	{
		ThirstItem item = Thirst.getInstance().getYAMLConfig().new ThirstItem(itemString);
		
		ItemStack is = new ItemStack(Material.valueOf(item.getItem()), 1);
		
		//casting due to spigot api subject to change.
		is.setData(new MaterialData(is.getType(), (byte) item.getMetaData()));

		int quenchPercent = item.getQuenchPercent();
		
		if (is.getType() == event.getItem().getType() && event.getItem().getData().toString().equals(is.getData().toString())) {
               if (Thirst.getInstance().getYAMLConfig().itemConsumption || ThirstManager.getThirst().getPlayerThirst(event.getPlayer()) != 100)
                   ThirstManager.getThirst().setThirst(event.getPlayer(), ThirstManager.getThirst().getPlayerThirst(event.getPlayer()) + quenchPercent);
               else {
                   event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', Thirst.getInstance().getYAMLConfig().itemConsumeMessage.replace("%player%", event.getPlayer().getName())));
                   event.setCancelled(true);
               }
           }
	}
}
 
開發者ID:GamerKing195,項目名稱:Thirst,代碼行數:26,代碼來源:PlayerItemConsumeListener.java

示例2: onItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent e){
    Player p = e.getPlayer();
    ItemStack item = e.getItem();
    Material type = item != null ? item.getType() : Material.AIR;
    int thirst = p.getLevel();

    if (type == Material.POTION && item.getDurability() == 0 && p.getInventory().getItemInMainHand().isSimilar(item)){
        p.getInventory().getItemInMainHand().setType(Material.AIR);

        for (ItemStack i : p.getInventory().getContents()){
            if (i.getType() == Material.GLASS_BOTTLE){
                i.setType(Material.AIR);
            }
        }

        p.setLevel(0);
        if (thirst + 256 >= 1000){
            p.setLevel(1000);
            return;
        }
        p.setLevel(thirst + 256);
        p.sendMessage(p.getLevel() + " // " + thirst + 256);
    }
}
 
開發者ID:cadox8,項目名稱:WC,代碼行數:26,代碼來源:Thirst.java

示例3: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.getItem().getType() == Material.POISONOUS_POTATO)
	{
		for (PotionEffect effect : player.getActivePotionEffects())
	        player.removePotionEffect(effect.getType());

		Random rand = new Random();
		if(rand.nextInt(10) + 1 <= 6)
		{
			player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0), true);
			player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 0), true);
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:19,代碼來源:PoisonousPotato.java

示例4: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
	if(event.isCancelled()) return;
	Player player = event.getPlayer();
	if(event.getItem().getType() == Material.BEETROOT)
	{
		int amp = 0;
		int dur = 200;
		for (PotionEffect effect : player.getActivePotionEffects())
		{
			if(effect.getType().equals(PotionEffectType.INCREASE_DAMAGE))
			{
				dur += effect.getDuration();
				if(dur > 600) dur = 600;
				player.removePotionEffect(effect.getType());
			}
		}
		player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, dur, amp));
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:22,代碼來源:BeetrootStrength.java

示例5: onPlayerItemConsumeEvent

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
	Player player = event.getPlayer();
	
	if (!WorldGuardUtils.hasBypass(player))
	{
		ItemMeta itemMeta = event.getItem().getItemMeta();
		if (itemMeta instanceof PotionMeta)
		{
			WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
		}
		else
		{
			Material material = event.getItem().getType();
			if (material == Material.MILK_BUCKET)
			{
				WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
			}
		}
	}
}
 
開發者ID:isokissa3,項目名稱:WorldGuardExtraFlagsPlugin,代碼行數:23,代碼來源:PlayerListener.java

示例6: onEat

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEat(final PlayerItemConsumeEvent event) {

	final PlayerStat stat = PlayerStat.FOOD_EATEN;

	// Get player
	final Player player = event.getPlayer();

	// Do general check
	if (!plugin.doGeneralCheck(player, stat))
		return;

	final String foodName = StatzUtil.getFoodName(event.getItem());

	if (foodName == null)
		return;

	// Update value to new stat.
	plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
			StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "foodEaten", foodName, "world",
					player.getWorld().getName()));

}
 
開發者ID:Staartvin,項目名稱:Statz,代碼行數:24,代碼來源:FoodEatenListener.java

示例7: onPlayerItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
	Player player = event.getPlayer();
	ItemStack item = event.getItem();
	
	// if the item is not a potion we don't want to care.
	if (item == null || item.getType() != Material.POTION) {
		return;
	}
	
	// if the potion has the durability of a strength 2 potion, tell them and cancel.
	if (item.getDurability() == 8233) {
		player.sendMessage(ChatColor.RED + "Strength II is disabled.");
		event.setCancelled(true);
	}
}
 
開發者ID:LeonTG,項目名稱:NoStrengthII,代碼行數:17,代碼來源:DrinkListener.java

示例8: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
    if(e.getItem() == null){
        return;
    }
    
	Player p = e.getPlayer();
    //deny potion
	if (p == null){
		return;
	}
    
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r != null && e.getItem().getType().equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)){
    	RPLang.sendMessage(p, "playerlistener.region.cantuse");
    	e.setCancelled(true);
    }
}
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:19,代碼來源:RPMine19.java

示例9: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
  public void onConsume(PlayerItemConsumeEvent e){
      if(e.getItem() == null){
          return;
      }
      
      Player p = e.getPlayer();
      Location l = p.getLocation();
      
      Region r = RedProtect.get().rm.getTopRegion(l);

//deny item usage
List<String> items = RPConfig.getGlobalFlagList(p.getWorld().getName()+".deny-item-usage.items");
  	if (e.getItem() != null && items.contains(e.getItem().getType().name())){
  		if (r != null && ((!RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && r.canBuild(p)) || 
  				(RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-claimed-rps") && !r.canBuild(p)))){
  			RPLang.sendMessage(p, "playerlistener.region.cantuse");
  			e.setCancelled(true);  
  			return;
  		}
  		if (r == null && !RPConfig.getGlobalFlagBool(p.getWorld().getName()+".deny-item-usage.allow-on-wilderness") && !RedProtect.get().ph.hasPerm(p, "redprotect.bypass.world")){
  			RPLang.sendMessage(p, "playerlistener.region.cantuse");
  			e.setCancelled(true);
	}
      }
  }
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:27,代碼來源:RPGlobalListener.java

示例10: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onConsume(PlayerItemConsumeEvent e){
    if(e.getItem() == null){
        return;
    }
    
	Player p = e.getPlayer();
    //deny potion
	if (p == null){
		return;
	}
	
    if(RPUtil.denyPotion(e.getItem(), p)){
    	e.setCancelled(true);                    
    }
}
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:17,代碼來源:RPPlayerListener.java

示例11: onConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.LOW) 
public void onConsume(PlayerItemConsumeEvent event) {
	if (ItemManager.getId(event.getItem()) == CivData.GOLDEN_APPLE) {
		CivMessage.sendError(event.getPlayer(), "You cannot use golden apples.");
		event.setCancelled(true);
		return;
	}
	
	if (event.getItem().getType().equals(Material.POTION)) {
		ConfigTechPotion pot = CivSettings.techPotions.get(Integer.valueOf(event.getItem().getDurability()));
		if (pot != null) {
			if (!pot.hasTechnology(event.getPlayer())) {
				CivMessage.sendError(event.getPlayer(), "You cannot use "+pot.name+" potions. You do not have the technology yet.");
				event.setCancelled(true);
				return;
			}
			if (pot.hasTechnology(event.getPlayer())) {
				event.setCancelled(false);
			}
		} else {
			CivMessage.sendError(event.getPlayer(), "You cannot use this type of potion.");
			event.setCancelled(true);
		}
	}
}
 
開發者ID:netizen539,項目名稱:civcraft,代碼行數:26,代碼來源:PlayerListener.java

示例12: OnPlayerConsumeEvent

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerConsumeEvent(PlayerItemConsumeEvent event) {
	ItemStack stack = event.getItem();

	/* Disable notch apples */
	if (ItemManager.getId(event.getItem()) == ItemManager.getId(Material.GOLDEN_APPLE)) {
		if (event.getItem().getDurability() == (short)0x1) {
			CivMessage.sendError(event.getPlayer(), "You cannot use notch apples. Sorry.");
			event.setCancelled(true);
			return;
		}
	}	

	if (stack.getType().equals(Material.POTION)) {
		int effect = event.getItem().getDurability() & 0x000F;			
		if (effect == 0xE) {
			event.setCancelled(true);
			CivMessage.sendError(event.getPlayer(), "You cannot use invisibility potions for now... Sorry.");
			return;
		}
	}
}
 
開發者ID:netizen539,項目名稱:civcraft,代碼行數:23,代碼來源:BlockListener.java

示例13: onPlayerItemConsume

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
/**
 * On player item consume.
 *
 * @param event the event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
	
	Player player = event.getPlayer();
	IPlayerConfEntry entry;
	
	if((entry = playerConf.get(player)) != null
			&& !entry.isAdminMod()) {
	
		IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(player.getLocation());
		
		if (!checkPermission(land, player, PermissionList.EAT.getPermissionType())) {
			messagePermission(player);
			event.setCancelled(true);
		}
	}
}
 
開發者ID:Tabinol,項目名稱:Factoid,代碼行數:23,代碼來源:PlayerListener.java

示例14: onConsumePotion

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsumePotion(PlayerItemConsumeEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("potion")) {
        if (event.getItem().getType() == Material.POTION) {
            Potion potion = Potion.fromItemStack(event.getItem());
            if (potion != null) {
                this.showPotionHologram(event.getPlayer(), potion.getEffects());
            }
        } else if (event.getItem().getType() == Material.GOLDEN_APPLE) {
            String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple");
            if (event.getItem().getDurability() == 1) {
                msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple");
            }
            Location l = event.getPlayer().getLocation().clone();
            l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
            HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple"));
        }
    }
}
 
開發者ID:DSH105,項目名稱:HoloAPI,代碼行數:20,代碼來源:IndicatorListener.java

示例15: onPlayerEat

import org.bukkit.event.player.PlayerItemConsumeEvent; //導入依賴的package包/類
@EventHandler
public void onPlayerEat(PlayerItemConsumeEvent e) {
    final Player player = e.getPlayer();
    ItemStack itemConsumed = e.getItem();
    if (itemConsumed.isSimilar(CraftingAndRecipes.redstoneApple())) {
        player.setVelocity(player.getVelocity().setY(0.4));
        player.sendMessage(ChatColor.RED + "[CPU] You just got shocked by eating a redstone apple!");
        player.sendMessage(ChatColor.RED + "[CPU] You can't move that well!");
        CPUPlugin.bukkitScheduler.scheduleSyncDelayedTask(CPUPlugin.plugin, new BukkitRunnable() {
            @Override
            public void run() {
                player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 2000, 1));
                player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 2000, 4));
            }
        }, 60);
    }
}
 
開發者ID:waicool20,項目名稱:CPU,代碼行數:18,代碼來源:EatsRedstoneApple.java


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