Editing effects of an enchanted golden apple

Discussion in 'Plugin Development' started by CreeperFan12346, May 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    CreeperFan12346

    Hi! I'm developing a plugin the edits the effects of an enchanted golden apple (or as some people call it, an "OP apple".). How would I do this?
     
  2. Offline

    xTigerRebornx

    xTrollxDudex likes this.
  3. Offline

    Onlineids


    To add on to what xTigerRebornx said you could get the data or durability of what there consuming and if its 1 its a enchanted golden apple
     
  4. Offline

    CreeperFan12346

  5. Offline

    xTigerRebornx

    CreeperFan12346 http://wiki.bukkit.org/Event_API_Reference If you don't already know how to listen to an event, read through that. You'll want to listen to the event that is on the other side of that link (PlayerItemConsumeEvent), then get the ItemStack from the event (the method to do this can be found at that link also), check if the ItemStack is a Golden Apple, check if it has a data/durability of 1 (for the enchanted golden apple), and then check the ItemStack's ItemMeta for a name and lore to determine if it is your "Special Golden Apple", and if it is, you'd apply your effects.
    For the 2nd part, which is canceling the event and manually taking the ItemStack away, you'd cancel the event (you can find out that at the first link for the Event API), then you'd get the item in hand (since this is what they are consuming), you'd check if its amount is > 1, and if it is, set its amount to its current amount - 1, and if it isn't greater then 1, you'd simply remove the ItemStack from their inventory.
     
  6. Offline

    CreeperFan12346

    I don't want a "Special Apple". I just want to change the effects of every enchanted golden apple.
     
  7. Offline

    xTigerRebornx

  8. Offline

    CreeperFan12346

    The link doesn't tell how to do most of that...
     
  9. Offline

    xTigerRebornx

  10. Offline

    CreeperFan12346

    I know. I meant both the links.

    xTigerRebornx
    I managed to get some code done, but when I attempt to eat the apple, it only gives speed for 1 second. Here's the code:
    Code:java
    1. package me.Creeps.Candy;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerItemConsumeEvent;
    9. import org.bukkit.inventory.meta.ItemMeta;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14.  
    15. public class Candy extends JavaPlugin implements Listener{
    16.  
    17.  
    18. public void onEnable(){
    19. getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22.  
    23.  
    24. @EventHandler
    25. public void onPlayerItemConsume(PlayerItemConsumeEvent e){
    26. if(e.getItem().getType() == Material.GOLDEN_APPLE ){
    27.  
    28. }
    29. Player p = e.getPlayer();
    30. ItemMeta pm = (ItemMeta) e.getItem().getItemMeta();
    31. if(pm.getDisplayName().equalsIgnoreCase("Candy")){
    32. p.sendMessage(ChatColor.YELLOW + "You ate " + ChatColor.GOLD + "candy! Enjoy your effects. ;)");
    33. p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10, 3));
    34. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10, 10));
    35. p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 10, 0));
    36. }
    37. if(!p.hasPermission("candy.eat")){
    38. p.sendMessage(ChatColor.RED + "You are not Super+! Donate for it here " + ChatColor.GREEN + " [URL]http://vontagemc.enjin.com/shop[/URL]");
    39.  
    40.  
    41.  
    42. }
    43.  
    44. }
    45. }
    46.  
    47.  
    48.  
    49.  
    50.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page