Solved Swim faster in water

Discussion in 'Plugin Development' started by klofno1, Jul 25, 2013.

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

    klofno1

    Does anyone know how to make a player swim faster in water?
    I need this for my mermaid plugin but I have no idea how to do this.
     
  2. Offline

    etaxi341

    klofno1 Maybe you could change the velocity of a player if he is moving and in water. Trigger it with the PlayerMoveEvent and then you need to get in which direction he is moving. Or you could give Players in Water Fly while they are in water because with fly, water don't makes you slower. Sorry for bad English.
     
  3. Offline

    chasechocolate

    You can give them a speed potion when they are in water. Simply listen for PlayerMoveEvent, check if the event.getTo().getBlock().getType() is Material.WATER or Material.STATIONARY_WATER, and then apply speed (player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1), true)).
     
    kaif21, AndyMcB1 and etaxi341 like this.
  4. Offline

    etaxi341

    chasechocolate A little bit offtopic vut congratulations for BukkitDev Staff!
     
    chasechocolate likes this.
  5. Offline

    chasechocolate

    Thanks :)
     
  6. Offline

    klofno1

    etaxi341 chasechocolate

    Somehow I do not get the potion effect. Btw, do these potion effects work under the sea? If I drink an ordinary potion (swiftness) , it does not work underwater.

    Code:
    package me.JonathanNLD.Mermaid;
     
     
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class MermaidListener implements Listener {
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if(player.hasPermission("Mermaid.basic") || player.getPlayer().isOp()){
                Material to = event.getTo().getBlock().getType();
                Block to2 = event.getTo().getBlock();
                if(to.equals(Material.WATER) || to2.equals(Material.STATIONARY_WATER)) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1), true);
            }
        }
     
      }
    }
    
     
  7. Offline

    etaxi341

    klofno1 You are doing it right. But I would try a Higher Potion Effect Level. Maybe it works with a higher level. If not you know Speed Potions don't work under water :D

    EDIT: But why do you once check the Block and once the Material of the Block? you should check the Material for Both Blocks and not once the Block and once the Material. And you don't get the Material with ".equals". Use == instead.
     
  8. Offline

    Samthelord1

    What etaxi341 originally said, mix the two ideas, if they're in water set fly mode to true.
     
  9. Offline

    klofno1

    Samthelord1 etaxi341 chasechocolate
    No effect appears :eek:

    Code:
    package me.JonathanNLD.Mermaid;
     
     
     
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class MermaidListener implements Listener {
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if(player.hasPermission("Mermaid.basic") || player.getPlayer().isOp()){
                Material m = event.getPlayer().getLocation().getBlock().getType();
                if (m == Material.STATIONARY_WATER || m == Material.WATER) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 999999999, 1), true);
                if (m == Material.AIR) {
                    player.removePotionEffect(PotionEffectType.NIGHT_VISION);
                }
            }
        }
     
      }
    }
     
  10. Offline

    etaxi341

    klofno1 Have you registered your Listener in your Main?
     
  11. Offline

    klofno1


    Oh I did not look at my main! Answer yes, but an error :

    Code:
     this.getServer().getPluginManager().registerEvents((Listener) new MermaidListener(this), this);
    Code:
    Multiple markers at this line
        - Listener cannot be resolved to a type
        - The constructor MermaidListener(Main) is undefined
        - The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments
        (Listener, Main)
    I fixed that, Ill check if it is working now
     
  12. Offline

    etaxi341

    klofno1 Change your registration line to this:
    Code:
    getServer().getPluginManager().registerEvents(new MermaidListener(), this);
    You don't need to cast it as a Listener when you already implemented Listener in the class.
     
  13. Offline

    klofno1

    etaxi341 chasechocolate

    What am I doing wrong? if a player gets out of the water it does nothing!

    Main:

    Code:
    package me.JonathanNLD.Mermaid;
     
    import java.util.logging.Logger;
     
    import me.JonathanNLD.Mermaid.MermaidListener;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
        private static final Logger log = Logger.getLogger("Minecraft");
        public static Main plugin;
     
        @Override
        public void onEnable(){
        getCommand("vHelp").setExecutor(this);
        getCommand("vList").setExecutor(this);
        getServer().getPluginManager().registerEvents(new MermaidListener(), this);
            log.info("Venificus has been enabled!");
        }
     
     
     
        @Override
        public void onDisable(){
            log.info("Venificus has been disabled!");
        }
    }
    
    MermaidListener

    Code:
    package me.JonathanNLD.Mermaid;
     
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class MermaidListener implements Listener {
     
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if(player.hasPermission("Mermaid.basic") || player.getPlayer().isOp()){
                Material m = event.getPlayer().getLocation().getBlock().getType();
                if (m == Material.STATIONARY_WATER || m == Material.WATER) {
    event.getPlayer().setAllowFlight(true);
                event.getPlayer().setFlying(true);
                player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 999999999, 1), true);
                event.getPlayer().sendMessage("You feel at home in the water.");
                //Material m1 = event.getPlayer().getLocation().getBlock().getType();
                if (m == Material.AIR) {
                event.getPlayer().sendMessage("The air weakens you.");
                player.removePotionEffect(PotionEffectType.NIGHT_VISION);
                event.getPlayer().setFlying(false);
    event.getPlayer().setAllowFlight(false);
                }
            }
        }
            }
      }
    
     
  14. Offline

    etaxi341

    klofno1 I wouldn't check if its Air. I would check if it's not Water and not Stationary Water. Just do else so if this case is not true he will get removed his fly and stuff. But I want to say how you do this, this plugin could cause server lag. Because this gets triggered for every player when he moves a little bit.
     
  15. Offline

    klofno1

    Thank you I got it working, thanks a lot! And thank you for the advice, I am working on something new, a command that turns you into a mermaid and when you are one, there is a delay of checking if you're in water or not.
     
Thread Status:
Not open for further replies.

Share This Page