@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);
}
}
java类org.bukkit.event.player.PlayerItemConsumeEvent的实例源码
Thirst.java 文件源码
项目:WC
阅读 28
收藏 0
点赞 0
评论 0
PoisonousPotato.java 文件源码
项目:SurvivalPlus
阅读 31
收藏 0
点赞 0
评论 0
@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);
}
}
}
BeetrootStrength.java 文件源码
项目:SurvivalPlus
阅读 32
收藏 0
点赞 0
评论 0
@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));
}
}
PlayerItemConsumeListener.java 文件源码
项目:Thirst
阅读 27
收藏 0
点赞 0
评论 0
@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);
}
}
}
}
PlayerListener.java 文件源码
项目:WorldGuardExtraFlagsPlugin
阅读 26
收藏 0
点赞 0
评论 0
@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);
}
}
}
}
FoodEatenListener.java 文件源码
项目:Statz
阅读 25
收藏 0
点赞 0
评论 0
@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()));
}
DrinkListener.java 文件源码
项目:NoStrengthII
阅读 25
收藏 0
点赞 0
评论 0
@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);
}
}
RPMine19.java 文件源码
项目:RedProtect
阅读 33
收藏 0
点赞 0
评论 0
@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);
}
}
RPGlobalListener.java 文件源码
项目:RedProtect
阅读 30
收藏 0
点赞 0
评论 0
@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);
}
}
}
RPPlayerListener.java 文件源码
项目:RedProtect
阅读 31
收藏 0
点赞 0
评论 0
@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);
}
}
PlayerListener.java 文件源码
项目:civcraft
阅读 27
收藏 0
点赞 0
评论 0
@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);
}
}
}
BlockListener.java 文件源码
项目:civcraft
阅读 31
收藏 0
点赞 0
评论 0
@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;
}
}
}
PlayerListener.java 文件源码
项目:Factoid
阅读 25
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
}
IndicatorListener.java 文件源码
项目:HoloAPI
阅读 28
收藏 0
点赞 0
评论 0
@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"));
}
}
}
EatsRedstoneApple.java 文件源码
项目:CPU
阅读 34
收藏 0
点赞 0
评论 0
@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);
}
}
PlayerListener.java 文件源码
项目:TCMinigames
阅读 25
收藏 0
点赞 0
评论 0
@EventHandler
public void onPotionDrink(PlayerItemConsumeEvent event){
if(Minigame.getCurrentMinigame()!=null){
switch(Minigame.getCurrentMinigame().getMap().getType()){
case CIRCLE_OF_BOOM:
if(Team.getTeam(event.getPlayer()).equals(Minigame.getObservers())){
event.setCancelled(true);
} else {
if(!Minigame.getCurrentMinigame().getState().equals(MatchState.STARTED)){
}
}
break;
case KEY_QUEST:
break;
case WATER_THE_MONUMENT:
break;
default:
break;
}
}
}
PlayerEventRegionsHandler.java 文件源码
项目:AntiPotionField
阅读 27
收藏 0
点赞 0
评论 0
/**
* Checks to see if the player is attempting to drink a potion, and checks
* the potion to see if it is allowed.
*
* @param event The PlayerItemConsumeEvent involving the player.
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerConsume(PlayerItemConsumeEvent event) {
if (event.getItem().getType() != Material.POTION) {
return;
}
// Check the type of potion in the player's hand
Potion potion = Potion.fromItemStack(event.getItem());
Collection<PotionEffect> effects = potion.getEffects();
for (PotionEffect e : effects) {
if (!(Util.canUsePotion(event.getPlayer(), e.getType()))) {
// If we get here, we cancel this event and all is done.
event.setCancelled(true);
event.getPlayer().sendMessage(ChatColor.RED + "You cannot use that potion here!");
Util.removeDisallowedEffects(event.getPlayer());
return; // We don't need to check any more.
}
}
}
DarkerNights.java 文件源码
项目:DarkerNights
阅读 26
收藏 0
点赞 0
评论 0
/**
* Fires when an item is consumed. As we are not altering the event,
* but we do want to know if it is cancelled, we run it on the Monitor
* priority.
*
* @param event Event to handle.
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemConsume(PlayerItemConsumeEvent event) {
if (event.getItem().getType() == Material.MILK_BUCKET) {
// We don't want to cancel the event, but we want to re-apply darkness after the event
// has completed - if needed, so that the player can't cheat using the milk.
final Player player = event.getPlayer();
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
DarkerNights.checkBlindness(player);
}
});
}
}
SurvivorsListener.java 文件源码
项目:RoyalSurvivors
阅读 33
收藏 0
点赞 0
评论 0
@EventHandler
public void onHealItemFullFood(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return;
final Player p = e.getPlayer();
if (!RUtils.isInInfectedWorld(p) || p.getFoodLevel() < 20) return;
final ItemStack hand = e.getItem();
if (hand == null || hand.getType() != Material.MELON || hand.getDurability() != (short) 14) return;
if (p.getHealth() >= p.getMaxHealth() && p.getFoodLevel() >= 20) return; // don't waste
onUseHealItem(new PlayerItemConsumeEvent(p, hand));
// until Bukkit fixes removing the last item in interact events, workaround
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
for (int slot = 0; slot < p.getInventory().getSize(); slot++) {
ItemStack is = p.getInventory().getItem(slot);
if (is == null) continue;
if (!is.equals(hand)) continue;
is.setAmount(is.getAmount() - 1);
p.getInventory().setItem(slot, is);
}
}
});
}
SurvivorsListener.java 文件源码
项目:RoyalSurvivors
阅读 30
收藏 0
点赞 0
评论 0
@EventHandler
public void onUseHealItem(PlayerItemConsumeEvent e) {
final Player p = e.getPlayer();
if (!RUtils.isInInfectedWorld(p)) return;
final ItemStack hand = e.getItem();
if (hand == null || hand.getType() != Material.MELON || hand.getDurability() != (short) 14) return;
if (p.getMaxHealth() == p.getHealth() && p.getFoodLevel() >= 20) {
e.setCancelled(true); // don't waste medpacks - should never happen, though
return;
}
double newHealth = p.getHealth() + 8D;
int newFood = p.getFoodLevel() + 8;
if (newHealth > p.getMaxHealth()) newHealth = p.getMaxHealth();
if (newFood > 20) newFood = 20;
p.setHealth(newHealth);
p.setFoodLevel(newFood);
}
ThirstListener.java 文件源码
项目:RoyalSurvivors
阅读 30
收藏 0
点赞 0
评论 0
@EventHandler
public void onDrinky(PlayerItemConsumeEvent e) {
final Player p = e.getPlayer();
final ItemStack hand = e.getItem();
if (hand == null || hand.getType() != Material.POTION || hand.getDurability() != (short) 0 || !RUtils.isInInfectedWorld(p))
return;
PConfManager pcm = PConfManager.getPConfManager(p);
float thirst = pcm.getFloat("thirst");
if (!pcm.isSet("thirst")) thirst = 1F;
if (thirst >= 1F) {
e.setCancelled(true); // let's not waste water bottles
return;
}
thirst += Config.thirstRestorePercent / 100F;
if (thirst > 1F) thirst = 1F;
pcm.set("thirst", thirst);
pcm.set("thirstSaturation", (float) Config.thirstSaturationMax);
p.setExp(thirst);
}
PotionDropGame.java 文件源码
项目:Arcadia-Spigot
阅读 28
收藏 0
点赞 0
评论 0
@EventHandler
public void onPotionUse(PlayerItemConsumeEvent event) {
if(event.getItem().getType() == Material.POTION) {
new BukkitRunnable() {
public void run() {
if(event.getPlayer().isOnline()) {
event.getPlayer().getInventory().remove(Material.GLASS_BOTTLE);
}
}
}.runTaskLater(this.getAPI().getPlugin(), 3L);
}
}
WaterBowl.java 文件源码
项目:SurvivalPlus
阅读 29
收藏 0
点赞 0
评论 0
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
if(!Survival.settings.getBoolean("Mechanics.Thirst.Enabled"))
{
if(event.isCancelled()) return;
Player player = event.getPlayer();
if(event.getItem().getType() == Material.BEETROOT_SOUP)
{
event.setCancelled(true);
}
}
}
RawMeatHunger.java 文件源码
项目:SurvivalPlus
阅读 29
收藏 0
点赞 0
评论 0
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
if(event.isCancelled()) return;
Random rand = new Random();
Player player = event.getPlayer();
switch(event.getItem().getType())
{
case RAW_BEEF:
case PORK:
case MUTTON:
case RAW_FISH:
case RAW_CHICKEN:
case ROTTEN_FLESH:
int hungerChance = rand.nextInt(10) + 1;
if(hungerChance >= 1 && hungerChance <= 8)
{
int dur = 600;
for (PotionEffect effect : player.getActivePotionEffects())
{
if(effect.getType().equals(PotionEffectType.HUNGER))
{
dur += effect.getDuration();
player.removePotionEffect(effect.getType());
}
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, dur, 0, false));
}
break;
default:
}
}
CookieHealthBoost.java 文件源码
项目:SurvivalPlus
阅读 24
收藏 0
点赞 0
评论 0
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsume(PlayerItemConsumeEvent event)
{
if(event.isCancelled()) return;
Player player = event.getPlayer();
if(event.getItem().getType() == Material.COOKIE)
{
int amp = -1;
int dur = 600;
for (PotionEffect effect : player.getActivePotionEffects())
{
if(effect.getType().equals(PotionEffectType.HEALTH_BOOST))
{
dur += effect.getDuration();
if(effect.getDuration() >= 300)
amp++;
if(effect.getDuration() >= 1200)
amp++;
if(effect.getDuration() >= 3600)
amp++;
player.removePotionEffect(effect.getType());
}
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, dur, amp));
player.setSaturation(player.getSaturation() + 4.6f);
}
}
InventoryListener.java 文件源码
项目:Arc-v2
阅读 34
收藏 0
点赞 0
评论 0
@EventHandler(priority = EventPriority.LOWEST)
public void onConsume(PlayerItemConsumeEvent event) {
Player player = event.getPlayer();
InventoryData data = InventoryData.getData(player);
boolean canCheckFastConsume = CHECK_MANAGER.canCheckPlayer(player, CheckType.FASTCONSUME);
if (canCheckFastConsume) {
// check and cancel if we failed.
boolean cancel = FAST_CONSUME.check(player, data);
event.setCancelled(cancel);
}
}
GameListener.java 文件源码
项目:SurvivalAPI
阅读 25
收藏 0
点赞 0
评论 0
/**
* Increase the Regeneration boost when a golden apple is eaten
*
* @param event Event
*/
@EventHandler
public void onItemConsume(PlayerItemConsumeEvent event)
{
if (this.game instanceof RunBasedGame && event.getItem().getType() == Material.GOLDEN_APPLE)
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 10 * 20, 1));
}
RottenPotionsModule.java 文件源码
项目:SurvivalAPI
阅读 28
收藏 0
点赞 0
评论 0
/**
* Give a random potion effect when a player eat rotten flesh
*
* @param event Event
*/
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
if (event.getItem().getType() == Material.ROTTEN_FLESH)
{
PotionEffectType effectType = PotionEffectType.values()[this.random.nextInt(PotionEffectType.values().length)];
if (effectType != null)
event.getPlayer().addPotionEffect(new PotionEffect(effectType, (int) this.moduleConfiguration.get("effect-time") * 20, 1));
}
}
ConstantPotionModule.java 文件源码
项目:SurvivalAPI
阅读 38
收藏 0
点赞 0
评论 0
/**
* Set the effect on the player when he consumes
* a milk bucket
*
* @param event Event
*/
@EventHandler(ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
if (event.getItem().getType() == Material.MILK_BUCKET && SamaGamesAPI.get().getGameManager().getMaxReconnectTime() != -1)
this.setEffectsOnPlayer(event.getPlayer());
}
RemoveItemOnUseModule.java 文件源码
项目:SurvivalAPI
阅读 28
收藏 0
点赞 0
评论 0
/**
* Delete the ItemStack
*
* @param event Event
*/
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event)
{
if(event.getItem() == null)
return;
ItemStack stack = event.getItem();
if(stack.getType().equals(Material.MUSHROOM_SOUP))
Bukkit.getScheduler().runTask(this.plugin, () -> event.getPlayer().getInventory().remove(Material.BOWL));
}