Full speed aim

Discussion in 'Archived: Plugin Requests' started by harrybridgen, Dec 6, 2012.

  1. Offline

    harrybridgen

    Plugin category: RPG (?)

    Suggested name: BlotheraAim

    What I want: When someone is aiming with a bow, they are running at full speed. Simple.

    Ideas for commands: No commands needed for this plugin.

    Ideas for permissions: BlotheraAim.Aim

    When I'd like it by: ASAP.
    PS: Add me on skype @ harrybridgen please.
     
  2. Offline

    app1egenius93

    Do you mind the effects a potion adds? (the particles mainly) as AFAIK no one has successfully achieved speed boost without adding a potion effect to the player
     
  3. Offline

    seiterseiter1

    I think the request is to be able to shoot a bow while sprinting without potions.
    Tell me if im wrong.
     
  4. Offline

    app1egenius93

    I think that's what he wants too, just don't think it's possible without, from what I've been seeing around the forums at least people have really buggy velocity changes and eventually just give up
     
  5. Offline

    drtshock

    Could just figure out exactly how much drawing a bow slows you down, then find the level of speed that speeds you up that much. Only problem is knowing how long they draw the bow. You can't know how long they draw the bow as you can't tell if they are holding right click. And there is no DrawBowEvent to check if a bow is being drawn :\
     
  6. Offline

    app1egenius93

    Didn't even think about that yet... hmm
     
  7. Offline

    drtshock

    If there was a way then I'd love to have it.
     
  8. Offline

    RingOfStorms

    Isn't this client sided anyways? So this would be a mod? Or am I wrong :O
     
  9. Offline

    drtshock

    Holding in right click, yes. I don't believe there is any other way to do it. With a mod you could also make it so their FOV doesn't change maybe? :eek: I've never worked with mods so I'm not sure.
     
  10. Offline

    seiterseiter1

    doesnt he just want the slowness taken out not the holding in right click.
     
  11. Offline

    drtshock

    But like I said, there is no EntityDrawBowEvent. Only PlayerInteractEvent then checking if it's a right click and item in hand.
     
  12. Offline

    seiterseiter1

    Ohhh yeah.
     
  13. Offline

    Cybermaxke

    Was there no getForce() method in the bowshootevent?
     
  14. Offline

    harrybridgen

    Basicly i need it so when someone is aiming with the bow, you don't slow down. I don't mind the FOV change, just the speed change.
     
  15. Offline

    1mpre55

    The speed change is client-sided and there is nothing that a server can do to cancel it. The only thing a server can do is to compensate the slowdown with a speed potion effect like this:
    Code:
    private HashMap<Player, PotionEffect> players;
     
    @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
    public void onBowDraw(PlayerInteractEvent e) {
        if ((e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
                && e.getMaterial().equals(Material.BOW) && e.getPlayer().getInventory().contains(Material.ARROW)) {
            PotionEffect current = null;
            int amplifier = 1; // FIXME calibrate this
            for (PotionEffect pe : e.getPlayer().getActivePotionEffects().toArray(new PotionEffect[0]))
                if (pe.getType().equals(PotionEffectType.SPEED)) {
                    current = pe;
                    amplifier += pe.getAmplifier();
                    break;
                }
            players.put(e.getPlayer(), current);
            e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 1200, amplifier), true);
        }
    }
    @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
    public void onShoot(EntityShootBowEvent e) {
        if (players.containsKey(e.getEntity())) {
            Player player = (Player)e.getEntity();
            player.removePotionEffect(PotionEffectType.SPEED);
            if (players.get(player) == null)
                player.addPotionEffect(players.get(player));
            players.remove(player);
        }
    }
    But this solution may be buggy and hacked clients can exploit it to get free speed potion effect. A much more elegant solution is to recommend a client-side mod to your players.
     
  16. Offline

    harrybridgen

    Could I at least give it a go?
     
  17. Offline

    1mpre55

    Sure, but it has a bug where if a player right clicks with a bow without holding it, the EntityShootBowEvent is never called, therefore the player just got a free 20 second speed boost.
    Download
    It has config.yml inside the jar if you need it.
    source code (open)

    Code:
    package com.impress.privateplugins.NoBowSlowdown;
     
    import java.util.HashMap;
     
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event.Result;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class NoBowSlowdown extends JavaPlugin implements Listener {
        private HashMap<Player, PotionEffect> players;
        private int amplifier, duration;
       
        @Override
        public void onEnable() {
            players = new HashMap<Player, PotionEffect>(4);
            amplifier = getConfig().getInt("effect-amplifier", 12);
            duration = getConfig().getInt("effect-duration", 400);
            getServer().getPluginManager().registerEvents(this, this);
            getLogger().info(getName() + " enabled");
        }
        @Override
        public void onDisable() {
            getLogger().info(getName() + " disabled");
        }
       
        @EventHandler (ignoreCancelled = false, priority = EventPriority.HIGHEST)
        public void onBowDraw(PlayerInteractEvent e) {
            if ((e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
                    && e.getMaterial() == Material.BOW && e.useItemInHand() != Result.DENY
                    && e.getPlayer().hasPermission("nobowslowdown.use") && e.getPlayer().getInventory().contains(Material.ARROW)) {
                PotionEffect current = null;
                int a = amplifier;
                for (PotionEffect pe : e.getPlayer().getActivePotionEffects().toArray(new PotionEffect[0]))
                    if (pe.getType().equals(PotionEffectType.SPEED)) {
                        current = pe;
                        a += pe.getAmplifier();
                        break;
                    }
                players.put(e.getPlayer(), current);
                e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, duration, a), true);
            }
        }
        @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST)
        public void onShoot(EntityShootBowEvent e) {
            if (players.containsKey(e.getEntity())) {
                Player player = (Player)e.getEntity();
                player.removePotionEffect(PotionEffectType.SPEED);
                if (players.get(player) != null)
                    player.addPotionEffect(players.get(player));
                players.remove(player);
            }
        }
    }
     
  18. Offline

    libraryaddict

    Could listen for packets. We see the player drawing his bow because of packets.
     
  19. Offline

    1mpre55

    And be forced to update this minor plugin every Minecraft update? No thank you.
     
  20. Offline

    harrybridgen

    Download don't work.
     
  21. Offline

    1mpre55

    Try this
    Or this:
    [​IMG]
     

Share This Page