mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Fixed /plan search resulting every player #414
This commit is contained in:
parent
7857732b5d
commit
f65fd5ec8c
@ -223,4 +223,8 @@ public class NicknamesTable extends UserIDTable {
|
|||||||
public String getColumnNick() {
|
public String getColumnNick() {
|
||||||
return columnNick;
|
return columnNick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColumnUserID() {
|
||||||
|
return columnUserID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,14 +260,13 @@ public class UsersTable extends UserIDTable {
|
|||||||
* @throws SQLException when an error at fetching the names happens.
|
* @throws SQLException when an error at fetching the names happens.
|
||||||
*/
|
*/
|
||||||
public List<String> getMatchingNames(String name) throws SQLException {
|
public List<String> getMatchingNames(String name) throws SQLException {
|
||||||
String searchString = "%" + name + "%";
|
String searchString = "%" + name.toLowerCase() + "%";
|
||||||
NicknamesTable nicknamesTable = db.getNicknamesTable();
|
NicknamesTable nicknamesTable = db.getNicknamesTable();
|
||||||
String sql = "SELECT " + columnName + " FROM " + tableName +
|
String sql = "SELECT DISTINCT " + columnName + " FROM " + tableName +
|
||||||
" WHERE " + columnName + " LIKE LOWER(?)" +
|
" WHERE " + columnName + " LIKE ?" +
|
||||||
" UNION SELECT " + columnName + " FROM " + tableName +
|
" UNION SELECT DISTINCT " + columnName + " FROM " + tableName +
|
||||||
" WHERE " + columnID + " =" +
|
" JOIN " + nicknamesTable + " on " + columnID + "=" + nicknamesTable + "." + nicknamesTable.getColumnUserID() +
|
||||||
" (SELECT " + columnID + " FROM " + nicknamesTable +
|
" WHERE " + nicknamesTable.getColumnNick() + " LIKE ?";
|
||||||
" WHERE " + nicknamesTable.getColumnNick() + " LIKE LOWER(?))";
|
|
||||||
|
|
||||||
return query(new QueryStatement<List<String>>(sql, 5000) {
|
return query(new QueryStatement<List<String>>(sql, 5000) {
|
||||||
@Override
|
@Override
|
||||||
@ -280,7 +279,10 @@ public class UsersTable extends UserIDTable {
|
|||||||
public List<String> processResults(ResultSet set) throws SQLException {
|
public List<String> processResults(ResultSet set) throws SQLException {
|
||||||
List<String> matchingNames = new ArrayList<>();
|
List<String> matchingNames = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
matchingNames.add(set.getString("name"));
|
String match = set.getString("name");
|
||||||
|
if (!matchingNames.contains(match)) {
|
||||||
|
matchingNames.add(match);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return matchingNames;
|
return matchingNames;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package main.java.com.djrapitops.plan.utilities;
|
package main.java.com.djrapitops.plan.utilities;
|
||||||
|
|
||||||
|
import com.djrapitops.plugin.StaticHolder;
|
||||||
import com.djrapitops.plugin.command.ISender;
|
import com.djrapitops.plugin.command.ISender;
|
||||||
import com.djrapitops.plugin.command.bukkit.BukkitCMDSender;
|
import com.djrapitops.plugin.command.bukkit.BukkitCMDSender;
|
||||||
import main.java.com.djrapitops.plan.Plan;
|
import main.java.com.djrapitops.plan.Plan;
|
||||||
@ -14,6 +15,7 @@ import main.java.com.djrapitops.plan.database.tables.UsersTable;
|
|||||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
@ -38,6 +40,11 @@ public class MiscUtilsTest {
|
|||||||
|
|
||||||
private SQLDB db;
|
private SQLDB db;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
StaticHolder.saveInstance(MiscUtils.class, Plan.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPlayerDisplayNameArgsPerm() {
|
public void testGetPlayerDisplayNameArgsPerm() {
|
||||||
String[] args = new String[]{"Rsl1122", "Test"};
|
String[] args = new String[]{"Rsl1122", "Test"};
|
||||||
@ -114,7 +121,8 @@ public class MiscUtilsTest {
|
|||||||
String exp2 = "TestName2";
|
String exp2 = "TestName2";
|
||||||
|
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
usersTable.registerUser(UUID.randomUUID(), 0L, exp1);
|
UUID uuid1 = UUID.randomUUID();
|
||||||
|
usersTable.registerUser(uuid1, 0L, exp1);
|
||||||
usersTable.registerUser(UUID.randomUUID(), 0L, exp2);
|
usersTable.registerUser(UUID.randomUUID(), 0L, exp2);
|
||||||
|
|
||||||
String search = "testname";
|
String search = "testname";
|
||||||
@ -134,9 +142,11 @@ public class MiscUtilsTest {
|
|||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
String userName = RandomData.randomString(10);
|
String userName = RandomData.randomString(10);
|
||||||
db.getUsersTable().registerUser(uuid, 0L, userName);
|
db.getUsersTable().registerUser(uuid, 0L, userName);
|
||||||
|
db.getUsersTable().registerUser(MockUtils.getPlayerUUID(), 1L, "Not random");
|
||||||
|
|
||||||
String nickname = "2" + RandomData.randomString(10);
|
String nickname = "2" + RandomData.randomString(10);
|
||||||
db.getNicknamesTable().saveUserName(uuid, nickname);
|
db.getNicknamesTable().saveUserName(uuid, nickname);
|
||||||
|
db.getNicknamesTable().saveUserName(MockUtils.getPlayerUUID(), "No nick");
|
||||||
|
|
||||||
String search = "2";
|
String search = "2";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user