Advertisement
Guest User

Java bukkit commands file

a guest
May 24th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.00 KB | None | 0 0
  1. package me.mttprvst13.modmode;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.World;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.inventory.ItemStack;
  15. import org.bukkit.inventory.PlayerInventory;
  16.  
  17. public class Commands implements CommandExecutor {
  18.  
  19.     public Main main;
  20.     Map<Integer, Map<String, Object>> info;
  21.     public String ticketsFile;
  22.     public ConfigAccessor tickets;
  23.     public FileConfiguration ticket;
  24.  
  25.     @Override
  26.     public boolean onCommand(CommandSender sender, Command cmd, String label,
  27.             String[] args) {
  28.  
  29.         if (cmd.getName().equalsIgnoreCase("sm")) {
  30.  
  31.             if (args.length < 1) {
  32.  
  33.             } else if (args[0].equalsIgnoreCase("on")) {
  34.  
  35.             } else if (args[0].equalsIgnoreCase("off")) {
  36.  
  37.             } else if (args[0].equalsIgnoreCase("group")){
  38.                            
  39.             }
  40.  
  41.         } else if (cmd.getName().equalsIgnoreCase("ticket")) {
  42.  
  43.             if (args.length < 1) {
  44.  
  45.                 sender.sendMessage(ChatColor.BLUE + "Ticket command help for "
  46.                         + ChatColor.GREEN + main.getDescription().getName()
  47.                         + " v" + main.getDescription().getVersion()
  48.                         + ChatColor.BLUE + "!");
  49.                 sender.sendMessage(ChatColor.LIGHT_PURPLE
  50.                         + "/ticket submit [reason]" + ChatColor.GOLD + " - "
  51.                         + ChatColor.BLUE + "Submit a ticket!");
  52.                 sender.sendMessage(ChatColor.LIGHT_PURPLE
  53.                         + "/ticket status [id]" + ChatColor.GOLD + " - "
  54.                         + ChatColor.BLUE
  55.                         + "Check the status of one of your tickets");
  56.                 sender.sendMessage(ChatColor.LIGHT_PURPLE + "/ticket mine"
  57.                         + ChatColor.GOLD + " - " + ChatColor.BLUE
  58.                         + "Get all the IDs of your tickets.");
  59.  
  60.             } else if (args[0].equalsIgnoreCase("submit")) {
  61.  
  62.                 if (sender instanceof Player) {
  63.  
  64.                     String reason = null;
  65.                     for (String word : args) {
  66.  
  67.                         reason = reason + " " + word;
  68.  
  69.                     }
  70.                     reason = reason.substring(args[0].length() + 1);
  71.  
  72.                     Player player = (Player) sender;
  73.  
  74.                     Map<String, Object> stuff = new HashMap<String, Object>();
  75.                     Map<String, Object> loca = new HashMap<String, Object>();
  76.  
  77.                     Location loc = player.getLocation();
  78.                     loca.put("x", loc.getX());
  79.                     loca.put("y", loc.getY());
  80.                     loca.put("z", loc.getZ());
  81.                     loca.put("world", loc.getWorld().getName());
  82.                    
  83.                     double health = player.getHealth();
  84.                     int hunger = player.getFoodLevel();
  85.                     String gm = player.getGameMode().toString();
  86.                     float exp = player.getExp();
  87.                     PlayerInventory inv = player.getInventory();
  88.                     ItemStack[] invcont = inv.getContents();
  89.                     ItemStack[] armour = inv.getArmorContents();
  90.  
  91.                     stuff.put("location", loca);
  92.                     stuff.put("health", health);
  93.                     stuff.put("hunger", hunger);
  94.                     stuff.put("gamemode", gm);
  95.                     stuff.put("experionce", exp);
  96.                     stuff.put("inventory", invcont);
  97.                     stuff.put("armour", armour);
  98.                     stuff.put("reason", reason);
  99.                     stuff.put("playername", player.getName());
  100.  
  101.                     int id = info.size() + 1;
  102.                     info.put(id, stuff);
  103.                    
  104.                     ticket.set("tickets", info);
  105.                     tickets.saveConfig("tickets", ticket);
  106.  
  107.                     player.sendMessage(ChatColor.GREEN
  108.                             + "Successfully submitted your ticket with an ID of "
  109.                             + Integer.toString(id) + "!");
  110.  
  111.                 } else {
  112.  
  113.                     sender.sendMessage(ChatColor.RED
  114.                             + "You must be a player to send that command.");
  115.  
  116.                 }
  117.  
  118.             } else if (args[0].equalsIgnoreCase("status")) {
  119.  
  120.                 if (args.length < 2) {
  121.  
  122.                     sender.sendMessage(ChatColor.RED + "You must put the ID of the ticket!");
  123.  
  124.                 } else {
  125.  
  126.                     String id = args[1];
  127.                     Map<String, Object> stuff = info.get(Integer.parseInt(id));
  128.  
  129.                     if (stuff == null) {
  130.  
  131.                         sender.sendMessage(ChatColor.RED + "There is no ticket with an ID of " + id);
  132.                         // sender.sendMessage(info.get(info.size()).get("playername").toString());
  133.  
  134.                     } else if (!sender.isOp() && !stuff.get("playername").toString().equalsIgnoreCase(sender.getName())) {
  135.  
  136.                         sender.sendMessage(ChatColor.RED + "That ticket does not belong to you!");
  137.  
  138.                     } else {
  139.  
  140.                         @SuppressWarnings("unchecked")
  141.                         Map<String, Object> location = (Map<String, Object>) stuff.get("location");
  142.                         World world = (World) location.get("world");
  143.                        
  144.                         sender.sendMessage(ChatColor.GREEN + "Status for ticket: " + id);
  145.                         sender.sendMessage("Location X: " + location.get("x"));
  146.                         sender.sendMessage("Location Y: " + location.get("y"));
  147.                         sender.sendMessage("Location Z: " + location.get("z"));
  148.                         sender.sendMessage("Location World: " + world.getName());
  149.                         sender.sendMessage("Health: " + stuff.get("health"));
  150.                         sender.sendMessage("hunger: " + stuff.get("hunger"));
  151.                         sender.sendMessage("EXP: " + stuff.get("experionce"));
  152.                         sender.sendMessage("Gamemode: " + stuff.get("gamemode"));
  153.                         sender.sendMessage("Reason: " + stuff.get("reason"));
  154.  
  155.                     }
  156.                 }
  157.  
  158.             } else if (args[0].equalsIgnoreCase("mine")) {
  159.  
  160.                 boolean found = false;
  161.                 for (Integer key : info.keySet()) {
  162.  
  163.                     Map<String, Object> stuff = info.get(key);
  164.  
  165.                     if (stuff.get("playername").toString().equalsIgnoreCase(sender.getName())) {
  166.  
  167.                         found = true;
  168.                         sender.sendMessage(ChatColor.GREEN
  169.                                 + "Found a ticket for you with an ID of "
  170.                                 + Integer.toString(key));
  171.  
  172.                     }
  173.  
  174.                 }
  175.  
  176.                 if (found == false) {
  177.  
  178.                     sender.sendMessage(ChatColor.RED
  179.                             + "No tickets could be found for you!");
  180.  
  181.                 }
  182.  
  183.             }
  184.  
  185.         }
  186.  
  187.         return false;
  188.     }
  189.  
  190.     /**
  191.      * @param args
  192.      */
  193.     @SuppressWarnings("unchecked")
  194.     public Commands(Main main) {
  195.  
  196.         this.main = main;
  197.        
  198.         tickets = new ConfigAccessor(main);
  199.         ticketsFile = "tickets.yml";
  200.        
  201.         tickets.createConfig(ticketsFile);
  202.         ticket = tickets.getConfig("tickets");
  203.        
  204.         if(ticket == null){
  205.             info = new HashMap<Integer, Map<String, Object>>();
  206.         }else{
  207.             info = (Map<Integer, Map<String, Object>>) ticket.getConfigurationSection("tickets");
  208.         }
  209.  
  210.     }
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement