Adding effect to the sender.

Discussion in 'Plugin Development' started by mrdude123, Jul 15, 2015.

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

    mrdude123

    The sender is not getting an effect put onto them. I want them to get the nausea effect, but it's not working. Any fixes?
    Code:
    package me.thecerealkill3r.russianroulette;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    public class RussianRouletteRunner implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player player = (Player) sender;
            if((sender instanceof Player))
            if(args.length == 0){
                sender.sendMessage(ChatColor.GREEN + "------------------------------------------------");
                sender.sendMessage(ChatColor.WHITE + " ");
                sender.sendMessage(ChatColor.GRAY +  "                    Russian Roulette");
                sender.sendMessage(ChatColor.GOLD + "              Try some of the commands below!");
                sender.sendMessage(ChatColor.RED + "    /russianroulette play [number of bullets (MAX 6)]");
                sender.sendMessage(ChatColor.BLUE + "" + ChatColor.ITALIC + "                    By TheCerealKill3r ");
                sender.sendMessage(ChatColor.GREEN + "------------------------------------------------");
                return true;
            }
            if(args.length > 2){
                sender.sendMessage(ChatColor.RED + "Too many arguments!");
                return true;
            }
            if(args[0].equalsIgnoreCase("play")){
                if(args.length < 2){
                    sender.sendMessage(ChatColor.RED + "You need to choose how many bullets are in the chamber. If you exceed 6 bullets, nothing will happen.");
                    return true;
                }else{
                    if(args[1].equalsIgnoreCase("0")){
                    sender.sendMessage(ChatColor.RED + "No bullets? You're a wimp.");
                    return true;
                    }
                    if(args[1].equalsIgnoreCase("1")){
                        sender.sendMessage(ChatColor.GREEN + "You have a " + ChatColor.YELLOW + "16%" + ChatColor.GREEN + " chance to die.");
                        sender.sendMessage(ChatColor.RED + "Your hands are sweaty, you're feeling nauseous...");
                        player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 2, 10));
                    }
                }
            }
           
            return false;
        }
    
    }
    
     
  2. Offline

    Zombie_Striker

    @mrdude123
    Are you sure you're putting in the right data, because it looks like you are asking to give the player confusion for 1/2 a second.
     
  3. Offline

    xJayD

    You're adding the PotionEffect for two ticks.. Hope you know that potion effect durations are based on ticks, not seconds.

    20 ticks = 1 second
     
  4. Offline

    567legodude

    @mrdude123 Also you are casting the sender to a player and then checking if the sender is a player after you already cast it.
     
  5. Offline

    Zombie_Striker

    @567legodude
    Although it doesn't make sense, because the player field would not be used since the console is not a Player, there would be no error; What he has is inefficent but will not create an error.

    As for what you are going to do, you don't need an If statement for each number (1,2,3 ect.). Instead, check if the number greater than 0 and then do the calculations of chances ((double)bullets/max*100 == chance) and use the Random.nextInt(chances) to select a random number ( (Random.nextInt(6)+1) will return a Random number between 1 and 6)
     
Thread Status:
Not open for further replies.

Share This Page