Solved Help getting coords

Discussion in 'Plugin Development' started by OppositeGamer, Apr 4, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    OppositeGamer

    Ok so I have a guild plugin that claims land. But it claims the land at the players position when they type the command. Then I just use listeners to get that coordinate and amplify it by 8. It all works fine. Now I just need to get it to unclaim land. I want to scan around the player for the location where they claimed. And the nearest one at that. So I thought I'd use a for loop. Im getting no luck. Any ideas?

    Code:
        try {
                if (args.length != 1) {
                    sender.sendMessage(ChatColor.RED + "Usage: /guild unclaim");
                } else {
                    if (!Util.inGuild(sender.getName())) {
                        sender.sendMessage("You must be in a guild!");
                    } else {
                        if (Util.getRole(sender.getName()).equalsIgnoreCase("officer") || Util.getRole(sender.getName()).equalsIgnoreCase("leader")) {
                                Player player = (Player) sender;
     
                                ResultSet result = null;
     
                                for (int i = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE id = (select Min(id) from Guilds)").getInt("id"); i <= SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE id = (select Max(id) from Guilds)").getInt("id"); i++) {
                                    result = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE id='" + i + "'");
     
                                    if (result.getString("area") == null || result.getString("area").equalsIgnoreCase("")) {
                                    } else {
                                        String[] checkedArea = result.getString("area").split("\\|");
                                        for (int v = 0; v < checkedArea.length; v++) {
                                            String[] ind = checkedArea[v].split(",");
                                            Location loc = new Location(Bukkit.getServer().getWorld(ind[0]), Double.parseDouble(ind[1]), Double.parseDouble(ind[2]), Double.parseDouble(ind[3]));
                                            for(int w = 0; w <= 8; w++) {
                                                int maxX_ = player.getLocation().getBlockX() + w;
                                                int maxY_ = player.getLocation().getBlockY() + w;
                                                int maxZ_ = player.getLocation().getBlockZ() + w;
                                               
                                                int minX_ = player.getLocation().getBlockX() - w;
                                                int minY_ = player.getLocation().getBlockY() - w;
                                                int minZ_ = player.getLocation().getBlockZ() - w;
                                               
                                                if (loc.getX() == Math.abs(minX_) || loc.getX() == Math.abs(maxX_)) {
                                                    if(Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
     
                                                        ResultSet result_ = SQLHandler.sqlite.query("SELECT * FROM Players WHERE player='" + sender.getName().toLowerCase() + "'");
                                                        ResultSet result__ = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE guild='" + result_.getString("guild") + "'");
                                                        SQLHandler.sqlite.query("UPDATE Guilds SET area='" +  result__.getString("area").replaceAll(player.getWorld().getName() + "," + Math.abs(maxX_) + "," + Math.abs(maxY_) + "," + Math.abs(maxZ_) + "|", "") + "' WHERE guild='" + result_.getString("guild") + "'");
                                                        sender.sendMessage("Land un-claimed at x=" + Math.abs(maxX_) + ", y=" + Math.abs(maxY_) + ", z=" + Math.abs(maxZ_) + "!");
                                                        Util.economy.withdrawPlayer(sender.getName(), Util.costToClaim());
                                                    }
                                                } else if (loc.getZ() == Math.abs(minZ_) || loc.getZ() == Math.abs(maxZ_)) {
                                                    if(Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
     
                                                        ResultSet result_ = SQLHandler.sqlite.query("SELECT * FROM Players WHERE player='" + sender.getName().toLowerCase() + "'");
                                                        ResultSet result__ = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE guild='" + result_.getString("guild") + "'");
                                                        SQLHandler.sqlite.query("UPDATE Guilds SET area='" +  result__.getString("area").replaceAll(player.getWorld().getName() + "," + Math.abs(maxX_) + "," + Math.abs(maxY_) + "," + Math.abs(maxZ_) + "|", "") + "' WHERE guild='" + result_.getString("guild") + "'");
                                                        sender.sendMessage("Land un-claimed at x=" + Math.abs(maxX_) + ", y=" + Math.abs(maxY_) + ", z=" + Math.abs(maxZ_) + "!");
                                                        Util.economy.withdrawPlayer(sender.getName(), Util.costToClaim());
                                                    }
                                                } else if (loc.getY() == Math.abs(minY_) || loc.getY() == Math.abs(maxY_)) {
                                                    if(Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
     
                                                        ResultSet result_ = SQLHandler.sqlite.query("SELECT * FROM Players WHERE player='" + sender.getName().toLowerCase() + "'");
                                                        ResultSet result__ = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE guild='" + result_.getString("guild") + "'");
                                                        SQLHandler.sqlite.query("UPDATE Guilds SET area='" +  result__.getString("area").replaceAll(player.getWorld().getName() + "," + Math.abs(maxX_) + "," + Math.abs(maxY_) + "," + Math.abs(maxZ_) + "|", "") + "' WHERE guild='" + result_.getString("guild") + "'");
                                                        sender.sendMessage("Land un-claimed at x=" + Math.abs(maxX_) + ", y=" + Math.abs(maxY_) + ", z=" + Math.abs(maxZ_) + "!");
                                                        Util.economy.withdrawPlayer(sender.getName(), Util.costToClaim());
                                                    }
                                                } else {
                                                    player.sendMessage("Not claimed");
                                                }
                                            }
                                        }
                                    }
                                }
                        } else {
                            sender.sendMessage("You must be an officer");
                        }
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
    New code:

    Code:
    @Override
        public void execute() {
     
            try {
                if (args.length != 1) {
                    sender.sendMessage(ChatColor.RED + "Usage: /guild unclaim");
                } else {
                    if (!Util.inGuild(sender.getName())) {
                        sender.sendMessage("You must be in a guild!");
                    } else {
                        if (Util.getRole(sender.getName()).equalsIgnoreCase("officer") || Util.getRole(sender.getName()).equalsIgnoreCase("leader")) {
                            Player player = (Player) sender;
     
                            ResultSet result = null;
     
                            for (int i = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE id = (select Min(id) from Guilds)").getInt("id"); i <= SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE id = (select Max(id) from Guilds)").getInt("id"); i++) {
                                result = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE id='" + i + "'");
     
                                if (result.getString("area") == null || result.getString("area").equalsIgnoreCase("")) {
                                } else {
                                    String[] checkedArea = result.getString("area").split("\\|");
                                    for (int v = 0; v < checkedArea.length; v++) {
                                        String[] ind = checkedArea[v].split(",");
                                        Location loc = new Location(Bukkit.getServer().getWorld(ind[0]), Double.parseDouble(ind[1]), Double.parseDouble(ind[2]), Double.parseDouble(ind[3]));
                                        for (int w = 0; w <= 8; w++) {
                                            int maxX_ = player.getLocation().getBlockX() + w;
                                            int maxY_ = player.getLocation().getBlockY() + w;
                                            int maxZ_ = player.getLocation().getBlockZ() + w;
     
                                            int minX_ = player.getLocation().getBlockX() - w;
                                            int minY_ = player.getLocation().getBlockY() - w;
                                            int minZ_ = player.getLocation().getBlockZ() - w;
     
                                            if (loc.getX() == maxX_ && loc.getY() == maxY_ && loc.getZ() == maxZ_) { //max max max
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, maxX_, maxY_, maxZ_);
                                                }
                                            } else if (loc.getX() == minX_ && loc.getY() == minY_ && loc.getZ() == minZ_) { // min min min
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, minX_, minY_, minZ_);
                                                }
                                            } else if (loc.getX() == maxX_ && loc.getY() == maxY_ && loc.getZ() == minZ_) { // max max min
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, maxX_, maxY_, minZ_);
                                                }
                                            } else if (loc.getX() == maxX_ && loc.getY() == minY_ && loc.getZ() == minZ_) { // max min min
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, maxX_, minY_, minZ_);
                                                }
                                            } else if (loc.getX() == minX_ && loc.getY() == maxY_ && loc.getZ() == maxZ_) { // min max max
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, minX_, maxY_, maxZ_);
                                                }
                                            } else if (loc.getX() == minX_ && loc.getY() == minY_ && loc.getZ() == maxZ_) { // min min max
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, minX_, minY_, maxZ_);
                                                }
                                            } else if (loc.getX() == maxX_ && loc.getY() == minY_ && loc.getZ() == maxZ_) { // max min max
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, maxX_, minY_, maxZ_);
                                                }
                                            } else if (loc.getX() == minX_ && loc.getY() == maxY_ && loc.getZ() == minZ_) { // min max min
                                                if (Util.getGuild(player.getName()).equalsIgnoreCase(result.getString("guild"))) {
                                                    unclaim(player, minX_, maxY_, minZ_);
                                                }
                                            } else {
                                                player.sendMessage("Not claimed");
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            sender.sendMessage("You must be an officer");
                        }
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
     
        }
     
        private void unclaim(Player player, int x, int y, int z) {
            try {
                ResultSet result_ = SQLHandler.sqlite.query("SELECT * FROM Players WHERE player='" + sender.getName().toLowerCase() + "'");
                ResultSet result__ = SQLHandler.sqlite.query("SELECT * FROM Guilds WHERE guild='" + result_.getString("guild") + "'");
                SQLHandler.sqlite.query("UPDATE Guilds SET area='" + result__.getString("area").replaceAll(player.getWorld().getName() + "," + x + "," + y + "," + z + "\\|", "") + "' WHERE guild='" + result_.getString("guild") + "'");
                sender.sendMessage("Land un-claimed at x=" + x + ", y=" + y + ", z=" + z + "!");
                Util.economy.withdrawPlayer(sender.getName(), Util.costToClaim());
            } catch (SQLException e) {
     
            }
        }
    But it's not finding the land. Only when Im standing directly on top of it. Any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page