Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.elacior.cityplugin.commands.city;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import de.elacior.cityplugin.Main;
- import de.elacior.cityplugin.manager.MySQL;
- import de.elacior.cityplugin.manager.TeleportManager;
- import de.elacior.cityplugin.other.Utiltools;
- public class HomeCommand implements CommandExecutor {
- public HomeCommand(Main plugin) {
- plugin.getCommand("sethome").setExecutor(this);
- plugin.getCommand("home").setExecutor(this);
- plugin.getCommand("delhome").setExecutor(this);
- plugin.getCommand("homelist").setExecutor(this);
- }
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- String command = cmd.getName();
- if (!(sender instanceof Player)) {
- return true;
- }
- Player player = (Player) sender;
- String uuid = player.getUniqueId().toString().replaceAll("-", "");
- if (command.equalsIgnoreCase("sethome")) {
- String homeName = "home";
- if (args.length == 1) {
- homeName = args[0];
- }
- if (args.length > 1) {
- Main.syntax("/sethome [HomeName]", player);
- return true;
- }
- ResultSet result = MySQL.select("SELECT COUNT(*) AS `amount` FROM `homes` WHERE `uuid` = '" + uuid + "'");
- try {
- if (result.next()) {
- int homeAmount = result.getInt("amount");
- ResultSet nextresult = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
- if (nextresult.next()) {
- if (homeAmount > Utiltools.getMaxHomes(player)) {
- player.sendMessage(Main.errorPrefix + "Du hast deine maximale Anzahl an Homes erreicht!");
- return true;
- }
- MySQL.execute("UPDATE `homes` SET `location`='" + Utiltools.getLocationString(player)
- + "' WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
- if (homeName.equalsIgnoreCase("home")) {
- player.sendMessage(Main.prefix + "Dein Home wurde erneuert!");
- return true;
- }
- player.sendMessage(Main.prefix + "Dein Home " + ChatColor.AQUA + homeName + ChatColor.GRAY
- + " wurde erneuert!");
- return true;
- }
- if (homeAmount + 1 > Utiltools.getMaxHomes(player)) {
- player.sendMessage(Main.errorPrefix + "Du hast deine maximale Anzahl an Homes erreicht!");
- return true;
- }
- MySQL.execute("INSERT INTO `homes`(`uuid`, `location`, `name`) VALUES ('" + uuid + "','"
- + Utiltools.getLocationString(player) + "','" + homeName + "')");
- if (homeName.equalsIgnoreCase("home")) {
- player.sendMessage(Main.prefix + "Dein Home wurde gesetzt!");
- return true;
- }
- player.sendMessage(Main.prefix + "Dein Home " + ChatColor.AQUA + homeName + ChatColor.GRAY + " wurde gesetzt!");
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- else if (command.equalsIgnoreCase("home")) {
- String homeName = "home";
- if (args.length == 1) {
- homeName = args[0];
- }
- if (args.length > 1) {
- Main.syntax("/home [HomeName]", player);
- return true;
- }
- ResultSet result = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
- try {
- if (result.next()) {
- String loc = result.getString("location");
- Location newLoc = Utiltools.getLocationFromString(loc);
- TeleportManager.teleport(player, newLoc, 30L, Main.prefix + "Willkommen Zuhause!");
- player.sendMessage(Main.prefix + "Der Teleport wurde eingeleitet!");
- return true;
- }
- else {
- if (args.length == 0) {
- if (homeName.equalsIgnoreCase("home")) {
- ResultSet resultlist = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "'");
- try {
- if (resultlist.next()) {
- String loc = result.getString("location");
- Location newLoc = Utiltools.getLocationFromString(loc);
- TeleportManager.teleport(player, newLoc, 30L, Main.prefix + "Willkommen Zuhause!");
- player.sendMessage(Main.prefix + "Der Teleport wurde eingeleitet!");
- return true;
- } else {
- player.sendMessage(Main.errorPrefix + "Du hast keine Homes gesetzt!");
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- return true;
- }
- }
- }
- player.sendMessage(Main.errorPrefix + "Dieses Home existiert nicht!");
- return true;
- }
- } catch (SQLException e) {
- e.printStackTrace();
- return true;
- }
- }
- if (command.equalsIgnoreCase("delhome")) {
- String homeName = "home";
- if (args.length == 1) {
- homeName = args[0];
- }
- if (args.length > 1) {
- Main.syntax("/delhome [HomeName]", player);
- return true;
- }
- ResultSet result = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
- try {
- if (result.next()) {
- MySQL.execute("DELETE FROM `homes` WHERE `uuid` = '" + uuid + "' AND `name` = '" + homeName + "'");
- player.sendMessage(Main.prefix + "Dein Home wurde erfolgreich gelöscht!");
- return true;
- }
- player.sendMessage(Main.errorPrefix + "Dieses Home existiert nicht!");
- return true;
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- if (command.equalsIgnoreCase("homelist")) {
- String homelist = "";
- ResultSet result = MySQL.select("SELECT * FROM `homes` WHERE `uuid` = '" + uuid + "'");
- try {
- while (result.next()) {
- String home = result.getString("name");
- homelist = homelist + ChatColor.AQUA + home + ChatColor.GRAY + ", ";
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- if (homelist.equalsIgnoreCase("")) {
- player.sendMessage(Main.errorPrefix + "Du hast keine Homes!");
- return true;
- }
- player.sendMessage(Main.prefix + "Deine Homes: " + homelist.substring(0, homelist.length() - 2));
- return true;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement