#setVelocity trouble

1 messages · Page 1 of 1 (latest)

wooden moon
#

i have this simple code in a Listener class.

    @EventHandler(priority=EventPriority.HIGH)
    public void onProjectileHit(ProjectileHitEvent event) {
        if (event.isCancelled()) return;
        if (event.getHitEntity() == null) return;

        getLogger().info(event.getHitEntity().getVelocity().toString());
        event.getHitEntity().setVelocity(new Vector(0, 4, 0));
        getLogger().info(event.getHitEntity().getVelocity().toString());
    }

when i shoot a stationary mob nothing happens to it, but when i shoot a mob that's falling or jumping up a block it gets launched into the sky. any advice?
(2nd logger statement outputs a y velocity of 4.0 even when the mob doesn't move)

#

anyone ran into this issue

wooden moon
#

when binding it to a command it doesn't occur

feral badger
wooden moon
#

alright thanks

#

i suspected that

wooden moon
#

do i have to add a getPlugin method with my main class (the one that extends JavaPlugin)?

feral badger
#

You actually only need to change the line with the Bukkit.getScheduler on your code

wooden moon
#

Idk how to get it tho

#

Could i see the method

wooden moon
#

or any other way to get it @feral badger? i never needed to get plugin class from another class

#

or wait would something like this work

Bukkit.getPluginManager().registerEvents(new MushroomBowEvents(this), this);

...

    Plugin plugin;
    public MushroomBowEvents(Plugin plugin) {
        this.plugin = plugin;
    }
``` ?
feral badger
#

Oh, that's right, you need the plugin for the scheduler.... Completely forgotten. You just need the few lines in your main.

  private static Main plugin = null;

  @Override
  public void onLoad() {
    plugin = this;
  }

  public static Main getPlugin() {
    return plugin;
  }
feral badger
wooden moon
#

alright thanks awesome