Do things to other players???

Discussion in 'Plugin Development' started by jackiejoe4, Mar 4, 2013.

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

    jackiejoe4

    hi! I am creating a plugin that allows you to easily add potion effects to youself! I ahve got it all figured out except for one thing, giving them to other players. It seems that whenever i type /p<potion> <player> it always gives them the healing potion effect please help!

    Code:
    Code:
    package com.jackiejoe4.potions;
     
    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.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class Potions extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");
    public static Potions 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;
    player.hasPermission("potions.all");
    if (cmd.getName().equalsIgnoreCase("pRemove")) {
    for (PotionEffect effect : player.getActivePotionEffects())
    player.removePotionEffect(effect.getType());
    player.sendMessage(ChatColor.GREEN + "All Potion effect removed!");
    }else if(commandLabel.equalsIgnoreCase("pHelp")){
    player.sendMessage(ChatColor.DARK_AQUA + "=------>" + ChatColor.GOLD + "Potions Help Menu" + ChatColor.DARK_AQUA + "<------=");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pRemove" + ChatColor.GRAY + " | Removes all potion effects!");
    player.sendMessage(ChatColor.GOLD + "-----------------------------------------------------");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pHealing" + ChatColor.GRAY + " | Adds healing potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pRegen" + ChatColor.GRAY + " | Adds Regeneration potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pSwiftness" + ChatColor.GRAY + " | Adds Speed potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pFireResist" + ChatColor.GRAY + " | Adds Fire Resistance potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pNightVision" + ChatColor.GRAY + " | Adds Night Vision potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pStrength" + ChatColor.GRAY + " | Adds Strength potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pInvisibility" + ChatColor.GRAY + " | Adds Invisibility potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pPosion" + ChatColor.GRAY + " | Adds Posion potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pWeakness" + ChatColor.GRAY + " | Adds Weakness potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pSlowness" + ChatColor.GRAY + " | Adds Slowness potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    player.sendMessage(ChatColor.AQUA + "=-->" + ChatColor.YELLOW + "/pHarming" + ChatColor.GRAY + " | Adds Harming potion effect, Level: 4, Duration: 10 mins (12000 ticks)");
    } else if(commandLabel.equalsIgnoreCase("pHealing")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Healing" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Healing Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pRegen")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Regeneration" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Regeneration Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pSwiftness")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Swiftness" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Swiftness Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pFireResist")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Fire Resistance" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Fire Resistance Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pNightVision")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Night Vision" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Night Vision Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pStrength")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Strength" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Strength Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pInvisibility")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Invisibility" + ChatColor.GREEN + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Invisibility Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pPoison")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Poison" + ChatColor.RED + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Posion Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pWeakness")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Weakness" + ChatColor.RED + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Weakness Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pSlowness")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Slowness" + ChatColor.RED + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Slowness Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
     
    } else if(commandLabel.equalsIgnoreCase("pHarming")){
    player.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 12000, 3));
    player.sendMessage(ChatColor.GOLD + "Harming" + ChatColor.RED + " potion effect added!");
    } else if(args.length == 1){
    if(player.getServer().getPlayer(args[0])!=null){
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 12000, 3));
    player.sendMessage(ChatColor.GREEN + "Someone has given you a" + ChatColor.AQUA + " Harming Potion " + ChatColor.GREEN + "effect!");
    }else{
    player.sendMessage(ChatColor.RED + "Player could not be found D:");
    }
    }
    return false;
    }
    }
    
     
  2. Offline

    ZeusAllMighty11

    tl;dr

    You need to check args length and make sure the player isn't null which it appears you did but your arguments don't seem correct for the glance I took
     
  3. Offline

    jackiejoe4

    Could you send a code example, perhaps do it to the /pHealing command?
    then i can do it to the rest of them?
     
  4. Offline

    Lars1011

    Also next time could you post your code on pastebin.com ? Would greatly appreciate it!
     
  5. Offline

    jackiejoe4

Thread Status:
Not open for further replies.

Share This Page