Solved How Can I Create A Custom Potion?

Discussion in 'Plugin Development' started by Shortninja66, Jan 2, 2015.

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

    Shortninja66

    I would like to make a plugin for my own server that would execute a command for a specific potion, for example "/potionspeed1", lets say this would give you a potion with Speed II for five minutes. Now my problem is that I know how to add commands and how to add status effects directly to a player, but I cannot figure out how to have a potion be spawned in with these custom times/amps. I understand that the Bukkit community prefers programmers to figure it out on their own, I respect that, but I am really stumped on this. Even just a simple method on how the potion could be created will be EXTREMELY helpful! Thanks.

    EDIT: I also know a plugin like this exists, but I want to implement economy into it. So like if I did "/potionspeed1", it would give me a potion with Speed II for five minutes AND take $500 from me. I have economy figured out though.
     
  2. Offline

    Skionz

    Use the command's arguments and Player#addPotionEffect() or something like that.
     
  3. Offline

    Shortninja66

    This would be for adding direct status effects, I would like to figure out how to CREATE a potion with these custom effects on it.
     
  4. Offline

    Skionz

    Why not just add each effect with Player#addPotionEffect?
     
  5. Offline

    Monkey_Swag

    @Shortninja66 wait so are you trying to make a command or a drinkable potion that'll give you the effects?
     
  6. Offline

    Shortninja66

    Well, both. A command that gives you a drinkable potion that has custom amp/time.

    Well I want it to be able to be used whenever the player chooses to use it, like a kit sort thing. Not just type a command and get a potion effect.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  7. Offline

    Skionz

    Check when the player consumes an ItemStack with specific properties and add your potion effect.
     
    Shortninja66 likes this.
  8. Offline

    Shortninja66

    Alright that sounds like a feasible option. I'll give it a try.
     
  9. Offline

    Windy Day

  10. Offline

    Shortninja66

    Alright I got it all working, but I have a small problem that I'm surprised I can't fix.. Basically the player right clicks on the potion, but it does NOT get removed from their inventory. Here is my code for the Listener, as I don't think the main class is at fault here:

    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event)
        {
             Player player = event.getPlayer();
           
             if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
                 if (player.getItemInHand().getItemMeta().hasDisplayName()){
                     if (player.getItemInHand().getItemMeta().getDisplayName() == "Speed III")
                     {
                         player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 600, 2));
                         player.getInventory().remove(player.getItemInHand());
                     }
    As you can see I added "player.getInventory().remove(player.ItemInHand());" but it does not remove the item?

    My bad, it appears "player.updateInventory();" fixed it, but I'm wondering, why is this method deprecated? Is there a replacement method?

    I think that using this could be simpler than a listener, I'll give it a shot.

    <merged posts ~Eya>
     
    Last edited by a moderator: Jan 5, 2015
Thread Status:
Not open for further replies.

Share This Page