Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package main.commands;
  2.  
  3.  
  4. import java.util.Random;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandExecutor;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.command.ConsoleCommandSender;
  12. import org.bukkit.craftbukkit.Main;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.plugin.Plugin;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17.  
  18. import net.minecraft.server.v1_11_R1.CommandExecute;
  19. public class CommandCustomSound extends CommandExecute implements Listener, CommandExecutor {
  20.  
  21.  
  22.  
  23.     @Override
  24.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  25.         if (cmd.getName().equalsIgnoreCase("csound")) {
  26.             if(sender.isOp()) {
  27.                 if (args.length == 2) {
  28.                     String player = args[0];
  29.                     int method = Integer.parseInt(args[1]);
  30.                     ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
  31.                     Plugin plugin = JavaPlugin.getPlugin(Main.class);
  32.                     Bukkit.getScheduler().runTaskLater(plugin, () -> {
  33.                         String command = "playsound mvendor.vendor1 master " + player + " ~ ~ ~ 100 1 1";
  34.                         Bukkit.dispatchCommand(console, command);
  35.                     }, 8);
  36.                    
  37.                     if (method == 1)
  38.                     {
  39.                         Random rand = new Random();
  40.                         int randomNum = rand.nextInt((3 - 1) + 1) + 1;
  41.                         System.out.println("Music Random Number: " + randomNum);   
  42.                         switch (randomNum) {
  43.                         case 1:
  44.                             String command = "playsound mvendor.vendor1 master " + player + " ~ ~ ~ 100 1 1";
  45.                             Bukkit.dispatchCommand(console, command);
  46.                             return true;
  47.                         case 2:
  48.                             String command2 = "playsound mvendor.vendor2 master " + player + " ~ ~ ~ 100 1 1";
  49.                             Bukkit.dispatchCommand(console, command2);
  50.                             return true;
  51.                         case 3:
  52.                             String command3 = "playsound mvendor.vendor3 master " + player + " ~ ~ ~ 100 1 1";
  53.                             Bukkit.dispatchCommand(console, command3);
  54.                             return true;
  55.                         }
  56.  
  57.  
  58.                     }else {
  59.                         sender.sendMessage(ChatColor.RED + "Wrong Method!");
  60.                         return true;
  61.                     }
  62.                 } else {
  63.                     sender.sendMessage(ChatColor.RED + "Not enough arguments!");
  64.                     return true;
  65.                 }                      
  66.             }else {
  67.                 sender.sendMessage(ChatColor.RED + "You are not OP!");
  68.                 return true;
  69.             }
  70.         }
  71.         return false;
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement