Advertisement
Guest User

Commands.java

a guest
Nov 21st, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.49 KB | None | 0 0
  1. package me.doom.fly;
  2.  
  3. import java.io.File;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.command.ConsoleCommandSender;
  13. import org.bukkit.configuration.file.FileConfiguration;
  14. import org.bukkit.configuration.file.YamlConfiguration;
  15. import org.bukkit.entity.Player;
  16. public class Commands implements CommandExecutor {
  17.    
  18.     public static File file = new File("");
  19.    
  20.     private static ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
  21.  
  22.     public String cChat(char s, String m) {
  23.         String msg = ChatColor.translateAlternateColorCodes(s, m);
  24.         return msg;
  25.     }
  26.    
  27.     @Override
  28.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  29.        
  30.         if (args.length == 3) {
  31.             if (!(sender instanceof Player)) { return false;}
  32.             if (cmd.getName().equalsIgnoreCase("hoh") && args[0].equalsIgnoreCase("team") && args[1].equalsIgnoreCase("join")) {
  33.                 String name = sender.getName().toString();
  34.                 // Getting the player's UUID from the Player file.
  35.                 file = new File("./plugins/HoH/players.yml");
  36.                 FileConfiguration data = YamlConfiguration.loadConfiguration(file);
  37.                 // Player's UUID & TEAM
  38.                 String uuid = data.getString(name);
  39.                 String team = Hash.getInstance().joinTeam.get(uuid);
  40.                 // Team check & Notifys an Admin
  41.                 if (team == null) {
  42.                     sender.sendMessage(cChat('&', Main.title + "&c&lERROR &ePlease contact an Administrator about a Team Issue."));
  43.                     return false;
  44.                    
  45.                 }
  46.                 if (team.equalsIgnoreCase("none")) {
  47.                     if (!(Hash.getInstance().gameSettings.get("State") == "Y")) { // Joining a Team
  48.                         // Setting the team and telling the user.
  49.                         Hash.getInstance().joinTeam.put(uuid, args[2]);
  50.                         // sender.sendMessage(cChat('&', Main.title + "&eJoined Team &c" + args[2]));
  51.                         // Notifying Console
  52.                         console.sendMessage(cChat('&', Main.title + " &ePlayer joined Team &c" + args[2]));
  53.                         Bukkit.broadcastMessage(cChat('&', Main.title + "&c" + name + "&e Joined Team &c" + args[2]));
  54.                         // Adds the team to a list.
  55.                         if (!(Hash.getInstance().teams.containsValue(args[2]))) {
  56.                             Hash.getInstance().teams.put(name, args[2]);
  57.                         }
  58.                         return true;
  59.                     } else {
  60.                         // Game already started
  61.                         console.sendMessage(cChat('&', Main.title + "&c&lPlayer Error &fTried joining team while game active."));
  62.                         sender.sendMessage(cChat('&', Main.title + "&eThe game has already started. You may not join a team."));
  63.                         return true;
  64.                     }
  65.                 } else {
  66.                     // Already in a team
  67.                     console.sendMessage(cChat('&', Main.title));
  68.                     sender.sendMessage(cChat('&', Main.title + "&eYou are already on a Team."));
  69.                     return true;
  70.                 }
  71.             }
  72.         }
  73.         if (args.length == 0) {
  74.             if (sender instanceof Player) {
  75.                 if (cmd.getName().equalsIgnoreCase("hoh")) {
  76.                     // Listing all the commands.
  77.                     sender.sendMessage(cChat('&', Main.title + "&e&lCommands"));
  78.                     sender.sendMessage(cChat('&', "&7/hoh &7- &eShows this menu"));
  79.                     sender.sendMessage(cChat('&', "&7/hoh team join &e<&7TeamName&e> &7-&e Adds you to a team"));
  80.                    
  81.                 }  
  82.             }
  83.         }
  84.  
  85.         if (args.length == 1) {
  86.             if (cmd.getName().equalsIgnoreCase("hoh") && args[0].equalsIgnoreCase("start")) {
  87.                 if (sender.hasPermission("hoh.start")) {
  88.                     String state = Hash.getInstance().gameSettings.get("State");
  89.                     if (state == "N") { // Game Start
  90.                         Hash.getInstance().gameSettings.put("State", "Y"); // Telling everything the game has started.
  91.                         Bukkit.getServer().broadcastMessage(cChat('&', Main.title + "&a&lGame has started."));  // Game start message.
  92.                     } else { // Game Already Started
  93.                         sender.sendMessage(cChat('&', Main.title + "&eGame already started."));
  94.                         return true;
  95.                     }
  96.                 } else { // Permission Error
  97.                     sender.sendMessage(cChat('&', Main.title + "&cYou do not have permission &ehoh.start"));
  98.                     return true;
  99.                 }
  100.             } else if (cmd.getName().equalsIgnoreCase("hoh") && args[0].equalsIgnoreCase("teams")) {
  101.                 List<String> l1 = new ArrayList<String>();
  102.                 l1.addAll(Hash.getInstance().teams.values());
  103.                
  104.                 sender.sendMessage(cChat('&', Main.title + "&eTeams&7:"));
  105.                 for (int i = 0; i < l1.size(); i++) { // Lists all of the teams
  106.                     int n = i + 1;
  107.                     sender.sendMessage(cChat('&', "&e" + n + "&e:" + "&c " + l1.get(i).toString()));
  108.                    
  109.                 }
  110.             }
  111.         }
  112.         return false;
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement