How do I remove the speed effect potion from horses?

Discussion in 'Spigot Plugin Development' started by caughtbiggay, May 18, 2019.

  1. I want to remove the speed potion effect from horses (if they have it) or completely prevent them from getting it in the first place, is it possible?
  2. Could you provide some code and more detail? How are they getting speed in the first place?
  3. from splash potions of speed, I simply want to remove the potion effect from horses without making a loop that checks 10000 or more entities every tick
  4. Maybe check the splash potion event and then iterate through all affected entities, then check if it's a horse? If yes remove the effect.
  5. Try this, just tested it out on 1.8 and it works perfectly for me.
    Code (Java):
    new BukkitRunnable() {

                public void run() {

                    for (final World w : getServer().getWorlds()) {
                        for (final Entity e : w.getEntities()) {

                            if (!(e instanceof Horse)) {

                            final Horse h = (Horse) e;

                            if (h.hasPotionEffect(PotionEffectType.SPEED)) {

            }.runTaskTimer(this, 0, 20);
    For your situation, it's probably best to put it in a BukkitRunnable and put in in your onEnable, that way it will scan all entities every so often (set to every 20 ticks or 1 second in my example) and if it's a horse and has the Speed potion effect, it will remove it.
  6. Every second can still be unoptimized if the number of entities is too big. I honestly don't know the capabilities of plugins though, so I won't be able to put an upper bound
  7. If they’re doing a survival/factions server of some sort, they could always add in a simple piece of code that checks entities that aren’t near any players and removes them every 10 minutes or so, so that it’s not too much of a load on the server.
  8. Maybe try checking when someone throws a splash potion of speed, check if theres a horse within like 3 or 4 blocks, and if there is, remove it.
  9. A more accurate approach would be to listen to PotionSplashEvent, get all affected entities using getAffectedEntities() and remove all types that are horses.
  10. I was really just trying to suggest to listen for a PotionSplashEvent and then check if horses were affected rather than check all the horses and see if they have speed effects.
  11. I never suggested this, unless you are not referring to me:
    What I suggested was to prevent the horse from getting the effects of any splash potion from the beginning.
  12. The thing is, that only accounts for potion splashes. If that’s all they need, then that works. But if they want to include effects given by plugins or the server, it’s probably best to have something that just scans all the entities.
  13. This hasn't been stressed out so I'm merely giving some more options. OP can suit themselves however they like.