Adding PotionEffects without the bubbles! (Code Example)

Discussion in 'Resources' started by CrazeDev, May 7, 2012.


Was this useful?

  1. Yes

  2. No

    0 vote(s)
Thread Status:
Not open for further replies.
  1. Offline


    (Notice: by using this code you are limiting your plugins reach to craftbutkkit servers only)

    (You will need to import the craftbukkit library instead of the typical bukkit library)

    (If this code isn't working: Make sure you have the craftbukkit.jar added into your project)

    (I am aware that this type of code is more commonly broken upon minecraft updating!)

    Now on to the fun stuff.

    A while ago I discovered the ability to add PotionEffects to players. I played around with adding various effects and discovered the ugly bubbles that were created along with the useful stat increases. I found this to be unacceptable, so I scoured the internet for a solution. Alas no solution was to be found. THUS, I took the challenge upon myself and wrote a series of functions that allows you to create the same PotionEffects without the appearance of those fugly bubbles.

    It is by no means perfect and I am 110% open to suggestions!

    This particular piece of code is meant to be instantiated for each player using it. That is why the "playersBuffs" variable is only storing 1 players information. You can obviously turn these functions into static utility functions and create your own method of storing the PotionEffects per player.

        //Stores the players recently used effects
        private Set<Integer> playersBuffs = new HashSet<Integer>();
        //Adds the potion effect without the graphical bubbles
        private void addPotionEffectNoGraphic(Player p, PotionEffect pe) {
            Packet41MobEffect pm = new Packet41MobEffect();
            pm.a = p.getEntityId(); //The entity ID
            pm.b = (byte)pe.getType().getId(); //The potion effect type
            pm.c = (byte)pe.getAmplifier(); //The amplifier
            pm.d = (short)pe.getDuration(); //The duration
            pm = null;
        //Remove the potion effect
        private void removePotionEffectNoGraphic(Player p, PotionEffectType pe) {
            Packet42RemoveMobEffect pr = new Packet42RemoveMobEffect();
            pr.a = p.getEntityId();
            pr.b = (byte)pe.getId();
            pr = null;
        //Removes all of the players stored potion effects
        private void removeAllPotionEffectsNoGrapic(Player p){
            for(Integer i : playersBuffs){
                removePotionEffectNoGraphic(p, PotionEffectType.getById(i));
        //Checks if a player has a certain potion effect
        private boolean hasEffectNoGraphic(PotionEffectType pet){
                return true;
                return false;
    Hopefully this has been useful! I certainly could have used this information a few days ago and I am happy to save you all time trying to figure this out.


    Could a mod move this to a relevant section? This section is obviously not the right one. (Maybe Plugin Development?)


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 25, 2016
  2. Offline

    King Sama

    Hi, this code is exactly what I needed, thank you very much. Unfortunately, I see that you haven't been online since the date you've posted this... I will assume that, as the post seems to imply, you are fine with others using this bit of code in their own plugins. Of course, I will give credit where due. :)
    CrazeDev likes this.
  3. Offline


    Use it all you want, I am glad someone will have use for it!
    devilquak likes this.
  4. Offline


    I know this is a dumb question, but I get a "CraftPlayer cannot be resolved to type" error for the two "((CraftPlayer)p) lines in your code. I'm no complete noob, but I'm stupid enough to not know how to fix this. How would I go about getting rid of this error?

    Edit: Forgot to mention, yes, I've imported CraftBukkit, but nothing I do will get rid of the error.
  5. Offline


    Have you referenced the CraftBukkit jar?
  6. Offline


    :p Right as you said that, I had edited my post. Yeah, I've imported it, and nothing I try will fix it. Sad thing is that I should really know this.
  7. Offline


    What IDE are you using?
  8. Offline


  9. Offline


    Can you give me a screenshot of the project explorer pane on the left with everything expanded (referenced libraries etc)?
    Also, is there a quick fix if you hover over the error?

    Sorry if I appear patronizing, but I've made some really simple, stupid mistakes before.
  10. Offline


    No quick fix, and nothing I do will fix it, which is what's puzzling me. I'll take a screenshot in a sec.
  11. Offline


    Can you add this to the top of the code?
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    devilquak likes this.
  12. Offline


    Jesus christ, I knew it was something stupid. For some reason I didn't think of that, thank you so much, no more errors.
  13. Offline


    I've made worse mistakes :)
    Glad it's fixed.
    Ultimate_n00b, re4ly and devilquak like this.
  14. Offline


    Sorry for not being overly responsive in this thread, I've moved on from modding of late.
  15. Offline


    import org.bukkit.craftbukkit.entity.CraftPlayer; dont work?
  16. Offline


    The actual package as of 7/12/13 is org.bukkit.craftbukkit.v1_6_R2
  17. Offline


    "import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;"
    netServerHandler -> netServerHandler cannot be resolved or is not a field
  18. Offline


Thread Status:
Not open for further replies.

Share This Page