2023-10-22 10:14:55 +08:00
|
|
|
package coloryr.allmusic.core.command;
|
|
|
|
|
|
|
|
|
|
import coloryr.allmusic.core.AllMusic;
|
|
|
|
|
import coloryr.allmusic.core.objs.music.SearchPageObj;
|
|
|
|
|
import coloryr.allmusic.core.utils.Function;
|
|
|
|
|
|
2024-04-17 22:15:12 +08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class CommandSelect extends ACommand {
|
2023-10-22 10:14:55 +08:00
|
|
|
@Override
|
|
|
|
|
public void ex(Object sender, String name, String[] args) {
|
2024-04-17 22:15:12 +08:00
|
|
|
if (AllMusic.getConfig().needPermission &&
|
2023-10-22 10:14:55 +08:00
|
|
|
AllMusic.side.checkPermission(name, "allmusic.search")) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.noPer);
|
2023-10-22 10:14:55 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SearchPageObj obj = AllMusic.getSearch(name);
|
|
|
|
|
if (obj == null) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.emptySearch);
|
2023-10-22 10:14:55 +08:00
|
|
|
} else if (!args[1].isEmpty() && Function.isInteger(args[1])) {
|
|
|
|
|
int a = Integer.parseInt(args[1]);
|
|
|
|
|
if (a == 0) {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.errorNum);
|
2023-10-22 10:14:55 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String[] ID = new String[1];
|
|
|
|
|
ID[0] = obj.getSong((obj.getPage() * 10) + (a - 1));
|
|
|
|
|
AllMusic.side.sendMessage(sender,
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.getMessage().search.choice.replace("%Num%", "" + a));
|
2023-10-22 10:14:55 +08:00
|
|
|
CommandEX.addMusic(sender, name, ID);
|
|
|
|
|
AllMusic.removeSearch(name);
|
|
|
|
|
} else {
|
2024-04-17 22:15:12 +08:00
|
|
|
AllMusic.side.sendMessage(sender, AllMusic.getMessage().search.errorNum);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2024-04-18 09:03:23 +08:00
|
|
|
public List<String> tab(String name, String[] args, int index) {
|
2024-04-17 22:15:12 +08:00
|
|
|
if (args.length == 1 || (args.length == 2 && args[1].isEmpty())) {
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
SearchPageObj obj = AllMusic.getSearch(name);
|
|
|
|
|
if (obj != null) {
|
|
|
|
|
for (int a = 0; a < obj.getIndex(); a++) {
|
|
|
|
|
list.add(String.valueOf(a));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
2023-10-22 10:14:55 +08:00
|
|
|
}
|
2024-04-17 22:15:12 +08:00
|
|
|
return Collections.emptyList();
|
2023-10-22 10:14:55 +08:00
|
|
|
}
|
|
|
|
|
}
|