2013-05-20 15:38:30 +02:00
|
|
|
package com.gmail.nossr50.commands.database;
|
|
|
|
|
2013-08-21 19:18:50 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2013-05-20 15:38:30 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
2013-08-22 15:11:33 +02:00
|
|
|
import org.bukkit.command.CommandExecutor;
|
2013-05-20 15:38:30 +02:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.TabExecutor;
|
2013-08-21 19:18:50 +02:00
|
|
|
import org.bukkit.util.StringUtil;
|
2013-05-20 15:38:30 +02:00
|
|
|
|
2013-09-10 15:28:07 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-08-22 15:11:33 +02:00
|
|
|
import com.gmail.nossr50.commands.experience.ConvertExperienceCommand;
|
|
|
|
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
|
|
|
import com.gmail.nossr50.datatypes.database.DatabaseType;
|
2013-05-20 15:38:30 +02:00
|
|
|
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
2013-09-10 15:28:07 +02:00
|
|
|
|
2013-05-20 15:38:30 +02:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
|
|
|
public class McconvertCommand implements TabExecutor {
|
2013-08-21 19:18:50 +02:00
|
|
|
private static final List<String> FORMULA_TYPES;
|
2013-08-22 15:11:33 +02:00
|
|
|
private static final List<String> DATABASE_TYPES;
|
|
|
|
private static final List<String> SUBCOMMANDS = ImmutableList.of("database", "experience");
|
|
|
|
|
|
|
|
private CommandExecutor databaseConvertCommand = new ConvertDatabaseCommand();
|
|
|
|
private CommandExecutor experienceConvertCommand = new ConvertExperienceCommand();
|
2013-08-21 19:18:50 +02:00
|
|
|
|
|
|
|
static {
|
2013-08-22 15:11:33 +02:00
|
|
|
ArrayList<String> formulaTypes = new ArrayList<String>();
|
2013-08-21 19:18:50 +02:00
|
|
|
|
|
|
|
for (FormulaType type : FormulaType.values()) {
|
2013-08-22 15:11:33 +02:00
|
|
|
formulaTypes.add(type.toString());
|
2013-08-21 19:18:50 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
Collections.sort(formulaTypes);
|
|
|
|
FORMULA_TYPES = ImmutableList.copyOf(formulaTypes);
|
2013-08-21 19:18:50 +02:00
|
|
|
}
|
2013-05-20 15:38:30 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
static {
|
|
|
|
ArrayList<String> databaseTypes = new ArrayList<String>();
|
2013-05-20 15:38:30 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
for (DatabaseType type : DatabaseType.values()) {
|
|
|
|
databaseTypes.add(type.toString());
|
|
|
|
}
|
2013-05-20 15:38:30 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
// Custom stuff
|
2013-10-05 23:07:06 +02:00
|
|
|
databaseTypes.remove(DatabaseType.CUSTOM.toString());
|
2013-08-21 19:18:50 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
if (mcMMO.getDatabaseManager().getDatabaseType() == DatabaseType.CUSTOM) {
|
|
|
|
databaseTypes.add(DatabaseManagerFactory.getCustomDatabaseManagerClass().getName());
|
|
|
|
}
|
2013-08-21 19:18:50 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
Collections.sort(databaseTypes);
|
|
|
|
DATABASE_TYPES = ImmutableList.copyOf(databaseTypes);
|
|
|
|
}
|
2013-05-20 15:38:30 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 2:
|
|
|
|
if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) {
|
|
|
|
return databaseConvertCommand.onCommand(sender, command, label, args);
|
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[1].equalsIgnoreCase("exp")) {
|
|
|
|
return experienceConvertCommand.onCommand(sender, command, label, args);
|
2013-05-20 15:38:30 +02:00
|
|
|
}
|
2013-08-21 19:18:50 +02:00
|
|
|
|
2013-08-22 15:11:33 +02:00
|
|
|
return false;
|
2013-05-20 15:38:30 +02:00
|
|
|
default:
|
2013-08-21 19:18:50 +02:00
|
|
|
return false;
|
2013-05-20 15:38:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
2013-08-21 19:18:50 +02:00
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
2013-08-22 15:11:33 +02:00
|
|
|
return StringUtil.copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList<String>(SUBCOMMANDS.size()));
|
|
|
|
case 2:
|
|
|
|
if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) {
|
2013-09-10 21:47:15 +02:00
|
|
|
return StringUtil.copyPartialMatches(args[0], DATABASE_TYPES, new ArrayList<String>(DATABASE_TYPES.size()));
|
2013-08-22 15:11:33 +02:00
|
|
|
}
|
2013-09-10 21:47:15 +02:00
|
|
|
|
|
|
|
if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[0].equalsIgnoreCase("exp")) {
|
|
|
|
return StringUtil.copyPartialMatches(args[0], FORMULA_TYPES, new ArrayList<String>(FORMULA_TYPES.size()));
|
2013-08-22 15:11:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ImmutableList.of();
|
2013-08-21 19:18:50 +02:00
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
2013-05-20 15:38:30 +02:00
|
|
|
}
|
|
|
|
}
|