Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.10 KB | None | 0 0
  1. package de.elacior.cityplugin.commands.city;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Location;
  8. import org.bukkit.command.Command;
  9. import org.bukkit.command.CommandExecutor;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12.  
  13. import de.elacior.cityplugin.Main;
  14. import de.elacior.cityplugin.manager.MySQL;
  15. import de.elacior.cityplugin.manager.TeleportManager;
  16. import de.elacior.cityplugin.other.Utiltools;
  17.  
  18. public class HomeCommand implements CommandExecutor {
  19.  
  20.     public HomeCommand(Main plugin) {
  21.         plugin.getCommand("sethome").setExecutor(this);
  22.         plugin.getCommand("home").setExecutor(this);
  23.         plugin.getCommand("delhome").setExecutor(this);
  24.         plugin.getCommand("homelist").setExecutor(this);
  25.     }
  26.  
  27.     @Override
  28.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  29.  
  30.         String command = cmd.getName();
  31.  
  32.         if (!(sender instanceof Player)) {
  33.             return true;
  34.         }
  35.  
  36.         Player player = (Player) sender;
  37.         String uuid = player.getUniqueId().toString().replaceAll("-", "");
  38.  
  39.         if (command.equalsIgnoreCase("sethome")) {
  40.             String homeName = "home";
  41.             if (args.length == 1) {
  42.                 homeName = args[0];
  43.             }
  44.             if (args.length > 1) {
  45.                 Main.syntax("/sethome [HomeName]", player);
  46.                 return true;
  47.             }
  48.  
  49.             ResultSet result = MySQL.select("SELECT COUNT(*) AS `amount` FROM `homes` WHERE `uuid` = '" + uuid + "'");
  50.             try {
  51.                 if (result.next()) {
  52.                     int homeAmount = result.getInt("amount");
  53.                     ResultSet nextresult = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
  54.                     if (nextresult.next()) {
  55.                         if (homeAmount > Utiltools.getMaxHomes(player)) {
  56.                             player.sendMessage(Main.errorPrefix + "Du hast deine maximale Anzahl an Homes erreicht!");
  57.                             return true;
  58.                         }
  59.                         MySQL.execute("UPDATE `homes` SET `location`='" + Utiltools.getLocationString(player)
  60.                                 + "' WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
  61.                         if (homeName.equalsIgnoreCase("home")) {
  62.                             player.sendMessage(Main.prefix + "Dein Home wurde erneuert!");
  63.                             return true;
  64.                         }
  65.                         player.sendMessage(Main.prefix + "Dein Home " + ChatColor.AQUA + homeName + ChatColor.GRAY
  66.                                 + " wurde erneuert!");
  67.                         return true;
  68.                     }
  69.                     if (homeAmount + 1 > Utiltools.getMaxHomes(player)) {
  70.                         player.sendMessage(Main.errorPrefix + "Du hast deine maximale Anzahl an Homes erreicht!");
  71.                         return true;
  72.                     }
  73.                     MySQL.execute("INSERT INTO `homes`(`uuid`, `location`, `name`) VALUES ('" + uuid + "','"
  74.                             + Utiltools.getLocationString(player) + "','" + homeName + "')");
  75.                     if (homeName.equalsIgnoreCase("home")) {
  76.                         player.sendMessage(Main.prefix + "Dein Home wurde gesetzt!");
  77.                         return true;
  78.                     }
  79.                     player.sendMessage(Main.prefix + "Dein Home " + ChatColor.AQUA + homeName + ChatColor.GRAY + " wurde gesetzt!");
  80.                     return true;
  81.                 }
  82.             } catch (SQLException e) {
  83.                 e.printStackTrace();
  84.             }
  85.         }
  86.  
  87.         else if (command.equalsIgnoreCase("home")) {
  88.             String homeName = "home";
  89.             if (args.length == 1) {
  90.                 homeName = args[0];
  91.             }
  92.             if (args.length > 1) {
  93.                 Main.syntax("/home [HomeName]", player);
  94.                 return true;
  95.             }
  96.  
  97.             ResultSet result = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
  98.             try {
  99.                 if (result.next()) {
  100.                     String loc = result.getString("location");
  101.                     Location newLoc = Utiltools.getLocationFromString(loc);
  102.                     TeleportManager.teleport(player, newLoc, 30L, Main.prefix + "Willkommen Zuhause!");
  103.                     player.sendMessage(Main.prefix + "Der Teleport wurde eingeleitet!");
  104.                     return true;
  105.                 }
  106.                 else {
  107.                     if (args.length == 0) {
  108.                         if (homeName.equalsIgnoreCase("home")) {
  109.                             ResultSet resultlist = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "'");
  110.                             try {
  111.                                 if (resultlist.next()) {
  112.                                     String loc = result.getString("location");
  113.                                     Location newLoc = Utiltools.getLocationFromString(loc);
  114.                                     TeleportManager.teleport(player, newLoc, 30L, Main.prefix + "Willkommen Zuhause!");
  115.                                     player.sendMessage(Main.prefix + "Der Teleport wurde eingeleitet!");
  116.                                     return true;
  117.                                 } else {
  118.                                     player.sendMessage(Main.errorPrefix + "Du hast keine Homes gesetzt!");
  119.                                     return true;
  120.                                 }
  121.                             } catch (SQLException e) {
  122.                                 e.printStackTrace();
  123.                                 return true;
  124.                             }
  125.                         }
  126.                     }
  127.                     player.sendMessage(Main.errorPrefix + "Dieses Home existiert nicht!");
  128.                     return true;
  129.                 }
  130.             } catch (SQLException e) {
  131.                 e.printStackTrace();
  132.                 return true;
  133.             }
  134.         }
  135.  
  136.         if (command.equalsIgnoreCase("delhome")) {
  137.  
  138.             String homeName = "home";
  139.  
  140.             if (args.length == 1) {
  141.                 homeName = args[0];
  142.             }
  143.  
  144.             if (args.length > 1) {
  145.                 Main.syntax("/delhome [HomeName]", player);
  146.                 return true;
  147.             }
  148.  
  149.             ResultSet result = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
  150.             try {
  151.                 if (result.next()) {
  152.                     MySQL.execute("DELETE FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
  153.                     player.sendMessage(Main.prefix + "Dein Home wurde erfolgreich gelöscht!");
  154.                     return true;
  155.                 }
  156.                 player.sendMessage(Main.errorPrefix + "Dieses Home existiert nicht!");
  157.                 return true;
  158.             }
  159.             catch (SQLException e) {
  160.                 e.printStackTrace();
  161.             }
  162.         }
  163.  
  164.         if (command.equalsIgnoreCase("homelist")) {
  165.             String homelist = "";
  166.  
  167.             ResultSet result = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "'");
  168.             try {
  169.                 while (result.next()) {
  170.                     String home = result.getString("name");
  171.                     homelist = homelist + ChatColor.AQUA + home + ChatColor.GRAY + ", ";
  172.                 }
  173.             } catch (SQLException e) {
  174.                 e.printStackTrace();
  175.             }
  176.             if (homelist.equalsIgnoreCase("")) {
  177.                 player.sendMessage(Main.errorPrefix + "Du hast keine Homes!");
  178.                 return true;
  179.             }
  180.             player.sendMessage(Main.prefix + "Deine Homes: " + homelist.substring(0, homelist.length() - 2));
  181.             return true;
  182.         }
  183.         return true;
  184.     }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement