kelson8

Night vision Test

Oct 3rd, 2020 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1. package me.Kelson;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.command.Command;
  5. import org.bukkit.command.CommandExecutor;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.potion.PotionEffect;
  9. import org.bukkit.potion.PotionEffectType;
  10.  
  11. public class NightVisionCommand implements CommandExecutor {
  12.     Commands plugin;
  13.  
  14.     public NightVisionCommand(Commands passedPlugin) {
  15.         this.plugin = passedPlugin;
  16.     }
  17.  
  18.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  19.  
  20.         Player player = (Player) sender;
  21.  
  22.         if(cmd.getName().equalsIgnoreCase("nv") && sender.hasPermission("kelson.nightvision")) {
  23.             if (args.length == 0) {
  24.                 player.sendMessage(Commands.main + "Error: Command usage /nv <on/off>");
  25.             }
  26.             if (args.length > 0 && args[0].equalsIgnoreCase("on")) {
  27.                 player.removePotionEffect(PotionEffectType.NIGHT_VISION);
  28.                 player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 9999, 1));
  29.                 sender.sendMessage(Commands.main + "You have enabled your night vision!");
  30.  
  31.  
  32.  
  33.             } else if (args.length > 0 && args[0].equalsIgnoreCase("off")) {
  34.                 player.removePotionEffect(PotionEffectType.NIGHT_VISION);
  35.                 sender.sendMessage(Commands.main + "You have disabled your night vision!");
  36.  
  37.  
  38.  
  39.         }
  40.             /*Player target = Bukkit.getPlayerExact(args[1]);
  41.             if(target == null) {
  42.                 sender.sendMessage(ChatColor.GREEN + args[1] + ChatColor.RED + "is not online!");
  43.                 return true;
  44.             }*/
  45.             // old if (args.length > 1 && args[1].equals(targetPlayer) && args[0].equalsIgnoreCase("on")) {
  46.                 // old Player targetPlayer = (Player) plugin.getServer().getPlayer(args[1]);
  47.  
  48.                 if (args.length == 2 && args[0].equalsIgnoreCase("on")) {
  49.                     Player targetPlayer = Bukkit.getPlayerExact(args[1]);
  50.  
  51.                     targetPlayer.removePotionEffect(PotionEffectType.NIGHT_VISION);
  52.                     targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 9999, 1));
  53.                     targetPlayer.sendMessage(Commands.main + "Your night vision has been enabled by " + sender.getName());
  54.  
  55.  
  56.                 }
  57.                 if (args.length == 2 && args[0].equalsIgnoreCase("off")) {
  58.                     Player targetPlayer = Bukkit.getPlayerExact(args[1]);
  59.  
  60.                     targetPlayer.removePotionEffect(PotionEffectType.NIGHT_VISION);
  61.                     targetPlayer.sendMessage(Commands.main + "Your night vision has been disabled by " + sender.getName());
  62.  
  63.                 }
  64.  
  65.  
  66.  
  67.         } //TODO make the nightvision command run on others, /nv <on/off> [player]
  68.         if(cmd.getName().equalsIgnoreCase("cleareff") && sender.hasPermission("kelson.effect.clear")){
  69.             player.removePotionEffect(PotionEffectType.NIGHT_VISION);
  70.         }
  71.  
  72.  
  73.         return false;
  74.     }
  75. }
  76.  
  77.  
Add Comment
Please, Sign In to add comment