Potion Effects?

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

Thread Status:
Not open for further replies.
  1. 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:
    1. package com.zinotia.second;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.*;
    12.  
    13. @SuppressWarnings("unused")
    14. public class main extends JavaPlugin {
    15.     public final Logger logger = Logger.getLogger("Minecraft");
    16.     public static main plugin;
    17.    
    18.     @Override
    19.     public void onDisable() {
    20.         PluginDescriptionFile pdffile = this.getDescription();
    21.         this.logger.info(pdffile.getName() + " Has Been Disabled");
    22.     }
    23.    
    24.  
    25.  
    26.     @Override public void onEnable(){
    27.         PluginDescriptionFile pdffile = this.getDescription();
    28.         this.logger.info(pdffile.getName() + "Version " + pdffile.getVersion() + "Has Been Enabled");
    29.        
    30.     }
    31.    
    32.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    33.         Player player = (Player) sender;
    34.         if(commandLabel.equalsIgnoreCase("run")) {
    35.             player.sendMessage(ChatColor.RED + "You Can Now Run Fast Forever.");
    36.             }
    37.         return false;
    38.        
    39.     }
    40.    
    41.     public boolean onComamand(CommandSender sender, Command cmd, String commandlabel, String[] args){
    42.         Player player = (Player) sender;
    43.         if(commandlabel.equalsIgnoreCase("walk")) {
    44.             player.sendMessage(ChatColor.RED + "You Have Stopped Running");
    45.            
    46.            
    47.         }
    48.         return false;
    49.     }
    50.    
    51.     public void run(){
    52.  
    53.    
    54.    
    55.     }
    56. }
     
  2. 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 (Text):
    1. PotionEffect speed = PotionEffectType.SPEED.createEffect(99999999999, 7);
    2.                 ((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 (Text):
    1. PotionEffect nospeed = PotionEffectType.SPEED.createEffect(1, 0);
    2.  
    3. ((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 (Text):
    1.  package com.zinotia.second;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.*;
    12.  
    13. @SuppressWarnings("unused")
    14. public class main extends JavaPlugin {
    15.     public final Logger logger = Logger.getLogger("Minecraft");
    16.     public static main plugin;
    17.  
    18.     @Override
    19.     public void onDisable() {
    20.         PluginDescriptionFile pdffile = this.getDescription();
    21.         this.logger.info(pdffile.getName() + " Has Been Disabled");
    22.     }
    23.  
    24.  
    25.  
    26.     @Override public void onEnable(){
    27.         PluginDescriptionFile pdffile = this.getDescription();
    28.         this.logger.info(pdffile.getName() + "Version " + pdffile.getVersion() + "Has Been Enabled");
    29.      
    30.     }
    31.  
    32.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    33.         Player player = (Player) sender;
    34.         if(commandLabel.equalsIgnoreCase("run")) {
    35.             player.sendMessage(ChatColor.RED + "You Can Now Run Fast Forever.");
    36.         PotionEffect speed = PotionEffectType.SPEED.createEffect(99999999999, 7);
    37.                 player.addPotionEffect(speed, true);
    38.         }
    39.     else if (commandlabel.equalsIgnoreCase("walk")) {
    40.             player.sendMessage(ChatColor.RED + "You Have Stopped Running")
    41.         PotionEffect nospeed = PotionEffectType.SPEED.createEffect(1, 0);
    42.                 player.addPotionEffect(nospeed, true);
    43.  
    44.     }
    45.         return false;
    46.       }
    47.      
    48.     }
     
    fireblast709 likes this.
  4. Thank you :) Time to get adding more stuff :)
     
Thread Status:
Not open for further replies.

Share This Page