Trying to get rid of particle effects

Discussion in 'Plugin Development' started by Jamesthatguy, May 14, 2013.

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

    Jamesthatguy

    Hello, i am trying to get rid of particle effects (little bubbles) of potions and I am a bit new to packets. I found this code from a while back but it does not seem to work and it gives me an error.

    private Set<Integer> test = new HashSet<Integer>();
    private void addPotionEffect(Player p, PotionEffect pe) {
    test.add(pe.getType().getId());
    Packet41MobEffect pm = new Packet41MobEffect();
    pm.a = p.getEntityId();
    pm.b = (byte)pe.getType().getId();
    pm.c = (byte)pe.getAmplifier();
    pm.d = (short)pe.getDuration();
    ((CraftPlayer)p).getHandle().netServerHandler.sendPacket(pm);
    pm = null;
    }

    Error: netServerHandler cannot be resolved or is not a field

    Could anyone tell me exactly what is wrong?
     
  2. Offline

    sirrus86

    Yeah, netServerHandler was used in older versions of Minecraft. Replace it with playerConnection and you should be all set.
     
  3. Offline

    Jamesthatguy

    hmm that's strange, Its now warning me this"The method addPotionEffect(Player, PotionEffect) from the type mine is never used locally" and i am getting an error on start up. http://pastie.org/7908366
     
  4. Offline

    sirrus86

    If your aim is to remove ALL potion particle effects (not just the ones you manually set) then there's a bit more to it.

    Your error is because you're building against a CraftBukkit build for MC 1.5.1, but you're running the plugin on a server for MC 1.5.2. Just update your build path.
     
  5. Offline

    devilquak

    Jamesthatguy

    The method warning means you're not even using the method -- you're importing someone else's code, and then never even using it.
     
  6. Offline

    Jamesthatguy

    Ah alright I expected it was something like that. But yea i would like to get rid of all the potion particle effects on a player when he has a potion effect. What exactly would i need to add to accomplish this?

    Alright, can you tell me how to use it to get rid of all particle effects on mobs and people. I really haven't done anything with packets before so i am a bit in the dark :)

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

    devilquak

    Jamesthatguy

    It's not an issue at all of what the actual method does, it's just a matter of Java knowledge and syntax. You're taking someone's way of doing one thing, but just letting it sit there, and never actually using that method anywhere in your code

    I'd recommend for you to brush up on your Java a little bit, and maybe learn a little more about how methods are used and implemented.

    To use the method, insert

    addPotionEffect(player, <some potion effect here>);

    where you want to add an effect to a player.
     
  8. Offline

    sirrus86

    You're gonna need to catch and modify PlayerConsumeItemEvent.
    Code:
    private Packet41MobEffect p41(LivingEntity entity, PotionEffect pe) {
        Packet41MobEffect packet = new Packet41MobEffect();
        packet.a = entity.getEntityId();
        packet.b = (byte)pe.getType().getId();
        packet.c = (byte)pe.getAmplifier();
        packet.d = (short)pe.getDuration();
        return packet;
    }
     
    @EventHandler
    public void onConsume(PlayerConsumeItemEvent event) {
        if (event.getItem().getType() == Material.POTION) { // Item is a potion
            event.setCancelled(true); // Stop the player from consuming it
            Player player = event.getPlayer();
            player.setItemInHand(Material.GLASS_BOTTLE); // Simulate that the potion was still consumed
            Potion potion = Potion.fromItemStack(event.getItem());
            for (PotionEffect effect : potion.getEffects()) {
                ((CraftPlayer)player).getHandle().playerConnection.sendPacket(p41(player, effect));
            }
        }
    }
    Optionally you could also catch splash potions with PotionSplashEvent.
     
  9. Offline

    Jamesthatguy

    I am a bit confused, I am get the concept but I do not think there is a playerconsumeitemevent.

    I appreciate the advice but everyone works differently and personally, i thrive in a trial and error environment. I have learned two other languages using this same tactic and have found it to be extremely effective. Is this not what communities like this are for? Everyone helps everyone to learn something or to accomplish something. Everyone needs a starting point and if everyone knew everything about java before coming to this community, this entire forum thread would be absolutely useless.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  10. Offline

    sirrus86

  11. Offline

    devilquak

    Jamesthatguy

    I work that exact same way, and trust me, it doesn't hurt to read up about this type of thing. I learned Java by myself, comepletely and utterly doing so with plain trial-and-error for the first couple of months. After I had gone as far as I could with that, the day I went to Oracle's Java-tutorial website, I learned more than I ever would have in 10 years of trial-and-error. You can only do that so much.

    Coincidentally, the very topic I was researching was the use of methods. I had used them before, albeit only by having others tell me exactly what to do, so I had never actually understood them, but after reading all about them, the way I was supposed to, I grasped the concept instantly, and had a blast. I urge you to reconsider, and not waste much of your time like I did, and just watch a few simple tutorials and guides on even the most basic components of Java.
     
  12. Offline

    Jamesthatguy

    So its working fine but I am getting something extremely weird. Whenever i drink a potion it works how it should, not showing the particle effects, but it gives me this error http://pastie.org/7908723 and it puts the glass bottle i just drank into one of my armor slots. If i try to take it out then the item will disappear but it replaces actual armor. I don't have the slightest clue as to why its doing this and i am running off the latest dev build.
     
  13. Offline

    sirrus86

    We'd need to see your PlayerListener class to know the cause.
     
  14. Offline

    Jamesthatguy

  15. Offline

    sirrus86

    PlayerListener, line 37:
    Code:
    Material block = event.getClickedBlock().getType();
    You have to check first that the player is actually clicking a block:
    Code:
    if (event.getClickedBlock() != null) {
        Material block = event.getClickedBlock().getType();
    }
     
  16. Offline

    Jamesthatguy

    Ah alright and i have one last question. Thanks for being really helpful. If i wanted to make it so when someone hits a block they get a potion effect without the particles how exactly would i do that since this method would not work Potion potion = Potion.fromItemStack(event.getItem()); . Instead of getting it from the potion he drank i need to get it from the potion he gets when he hits the block like so player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,2400 ,20)); . How would I get that instead of getting the potion he drank?
     
  17. Offline

    sirrus86

    Code:
    ((CraftPlayer)player).getHandle().playerConnection.sendPacket(p41(player, new PotionEffect(PotionEffectType.SPEED, 2400, 20)));
     
  18. Offline

    Jamesthatguy

    Thanks a ton man!
     
Thread Status:
Not open for further replies.

Share This Page