Potion Effects?

Discussion in 'Plugin Development' started by Zinotia, Nov 4, 2012.

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

    Zinotia

    I'm currently developing a plugin which uses potion effects, I'm new to Java and the Bukkit API, and I was wondering if you could help me with this problem.
    So far I have it so when they type /run it sends a message to them saying 'You can now run really fast forever.'

    But... How do I give the player the effect of the speed potion and for it to last forever?

    This is the code I have so far:

    PHP:
    package com.zinotia.second;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.*;
     
    @
    SuppressWarnings("unused")
    public class 
    main extends JavaPlugin {
        public final 
    Logger logger Logger.getLogger("Minecraft");
        public static 
    main plugin;
       
        @
    Override
        
    public void onDisable() {
            
    PluginDescriptionFile pdffile this.getDescription();
            
    this.logger.info(pdffile.getName() + " Has Been Disabled");
        }
       
     
     
        @
    Override public void onEnable(){
            
    PluginDescriptionFile pdffile this.getDescription();
            
    this.logger.info(pdffile.getName() + "Version " pdffile.getVersion() + "Has Been Enabled");
           
        }
       
        public 
    boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args){
            
    Player player = (Playersender;
            if(
    commandLabel.equalsIgnoreCase("run")) {
                
    player.sendMessage(ChatColor.RED "You Can Now Run Fast Forever.");
                }
            return 
    false;
           
        }
       
        public 
    boolean onComamand(CommandSender senderCommand cmdString commandlabelString[] args){
            
    Player player = (Playersender;
            if(
    commandlabel.equalsIgnoreCase("walk")) {
                
    player.sendMessage(ChatColor.RED "You Have Stopped Running");
               
               
            }
            return 
    false;
        }
       
        public 
    void run(){
     
       
       
        }
    }
     
  2. Offline

    fireblast709

    You would need an ArrayList that keeps track of people that are running (where the run command adds them and the walk command removes them). And you would need a scheduler that prolongs the potioneffect. http://wiki.bukkit.org/Scheduler_Programming
     
  3. Offline

    Sheepii

    Code:
    PotionEffect speed = PotionEffectType.SPEED.createEffect(99999999999, 7);
                    ((Player)sender).addPotionEffect(speed, true);
    ^ to turn it on. The large number is the time (don't change that unless you know you want to), and the 7 is the strength.

    Code:
    PotionEffect nospeed = PotionEffectType.SPEED.createEffect(1, 0);
     
    ((Player)sender).addPotionEffect(nospeed, true);
    ^ to turn it off. (Change nothing)

    Unless they're playing on your server non-stop for 3168 years. I don't think it will turn off.

    So, a completed code would be:
    Code:
     package com.zinotia.second;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.*;
     
    @SuppressWarnings("unused")
    public class main extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static main plugin;
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + " Has Been Disabled");
        }
     
     
     
        @Override public void onEnable(){
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + "Version " + pdffile.getVersion() + "Has Been Enabled");
         
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("run")) {
                player.sendMessage(ChatColor.RED + "You Can Now Run Fast Forever.");
            PotionEffect speed = PotionEffectType.SPEED.createEffect(99999999999, 7);
                    player.addPotionEffect(speed, true);
            }
        else if (commandlabel.equalsIgnoreCase("walk")) {
                player.sendMessage(ChatColor.RED + "You Have Stopped Running")
            PotionEffect nospeed = PotionEffectType.SPEED.createEffect(1, 0);
                    player.addPotionEffect(nospeed, true);
     
        }
            return false;
          }
         
        }
     
    fireblast709 likes this.
  4. Offline

    Zinotia

    Thank you :) Time to get adding more stuff :)
     
Thread Status:
Not open for further replies.

Share This Page