0

这是我的世界的插件。它应该使用在配置中设置的客户 ID 拉出玩家并在游戏中显示他们。相反,它会吸引所有人,无论他们的客户 ID 是什么。

if(cmd.getName().equalsIgnoreCase("getaward"))
    {
        Player player = (Player)sender;
        try {
            Class.forName("com.mysql.jdbc.Driver");

        con = DriverManager.getConnection (dbUrl,dbUser,dbPass);

    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM `votesdb` WHERE `nick` = '"+player.getName().substring(0,player.getName().length()/2)+"' AND `customer_id` LIKE "+config.getString("customer_id")+"");
    //ResultSet rs = stmt.executeQuery("SELECT nick,votes FROM `votesdb` WHERE nick='"+player.getName()+" LIMIT 1");
    if(rs.next())
    {
        if(rs.getInt("votes")!=0)
        {
            player.sendMessage(ChatColor.GREEN+"[VFD]"+ChatColor.AQUA+"Thanks for voting! You will find something special in your inventory. :)");
            bukkit.broadcastMessage(ChatColor.GREEN+"[VFD]"+ChatColor.AQUA+player.getDisplayName()+" has been rewarded for Voting for the Server!");
            stmt.executeUpdate("UPDATE `votesdb` SET flag=0 WHERE `nick` LIKE '"+player.getDisplayName().substring(0,player.getDisplayName().length()/2)+"'");
            player.getInventory().addItem(new ItemStack(this.matID,this.matAmt));


        }
        else
        {
            player.sendMessage(ChatColor.RED+"You have already claimed your reward.");
        }   
    }
    else
    {
        player.sendMessage(ChatColor.RED+"We could not find you in the database! Please make sure you used the correct name when you voted!");
    }
4

1 回答 1

1
  1. 让您的查询尽可能简单,看看它是否有效,然后才能朝着您的目标前进。
  2. 除了客户 ID 之外,任何其他条件都没有任何意义。您说您需要所有具有该客户 ID 的玩家。
  3. 如前所述,ID 应该被限制为单个值,而不是像某个字符串。
于 2012-04-14T11:16:04.250 回答