mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-09-07 01:08:40 +02:00
Lazy command initialization
This commit is contained in:
parent
870495ac1a
commit
faf6cbea0f
@ -613,9 +613,9 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
*/
|
||||
public void registerCommand(final SubCommand c) {
|
||||
if (c.getCommand() != null) {
|
||||
MainCommand.instance.addCommand(c);
|
||||
MainCommand.getInstance().addCommand(c);
|
||||
} else {
|
||||
MainCommand.instance.createCommand(c);
|
||||
MainCommand.getInstance().createCommand(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ import com.plotsquared.bukkit.generator.HybridGen;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "cluser",
|
||||
command = "cluster",
|
||||
aliases = {"clusters"},
|
||||
category = CommandCategory.ACTIONS,
|
||||
requiredType = RequiredType.PLAYER,
|
||||
|
@ -46,11 +46,18 @@ import com.intellectualsites.commands.CommandManager;
|
||||
*/
|
||||
public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
|
||||
public static MainCommand instance = new MainCommand();
|
||||
private static MainCommand instance;
|
||||
|
||||
public static MainCommand getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MainCommand();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private MainCommand() {
|
||||
super(null, new ArrayList<Command<PlotPlayer>>());
|
||||
List<SubCommand> toAdd = Arrays.asList(
|
||||
List<SubCommand> toAdd = new ArrayList<>(Arrays.asList(
|
||||
new Buy(), new Save(), new Load(),
|
||||
new Template(), new Download(),
|
||||
new Update(), new Template(),
|
||||
@ -74,7 +81,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
new Trust(), new DebugExec(), new FlagCmd(),
|
||||
new Target(), new DebugFixFlags(), new Move(),
|
||||
new Condense(), new Condense(), new Copy(),
|
||||
new Chat());
|
||||
new Chat()));
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
toAdd.add(new Cluster());
|
||||
}
|
||||
@ -91,7 +98,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
}
|
||||
|
||||
public static ArrayList<Command<PlotPlayer>> getCommands(final CommandCategory category, final PlotPlayer player) {
|
||||
ArrayList<Command<PlotPlayer>> cmds = instance.getCommands();
|
||||
ArrayList<Command<PlotPlayer>> cmds = getInstance().getCommands();
|
||||
for (Iterator<Command<PlotPlayer>> iter = cmds.iterator(); iter.hasNext();){
|
||||
Command<PlotPlayer> cmd = iter.next();
|
||||
if ((category != null && (cmd.getCategory().equals(category))) || !player.hasPermission(cmd.getPermission())) {
|
||||
@ -235,7 +242,7 @@ public class MainCommand extends CommandManager<PlotPlayer> {
|
||||
builder.append(" ");
|
||||
}
|
||||
}
|
||||
instance.handle(player, builder.toString());
|
||||
getInstance().handle(player, builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
} else {
|
||||
getServer().getPluginManager().registerEvents(new WEListener(), this);
|
||||
WorldEdit.getInstance().getEventBus().register(new WESubscriber());
|
||||
MainCommand.instance.createCommand(new WE_Anywhere());
|
||||
MainCommand.getInstance().createCommand(new WE_Anywhere());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
return null;
|
||||
}
|
||||
final Set<String> tabOptions = new HashSet<>();
|
||||
ArrayList<Command<PlotPlayer>> commands = MainCommand.instance.getCommands();
|
||||
ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
|
||||
String best = new StringComparison(strings[0], commands).getBestMatch();
|
||||
tabOptions.add(best);
|
||||
final String arg = strings[0].toLowerCase();
|
||||
for (final Command<PlotPlayer> cmd : MainCommand.instance.getCommands()) {
|
||||
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
||||
String label = cmd.getCommand();
|
||||
if (!label.equalsIgnoreCase(best)) {
|
||||
if (label.startsWith(arg)) {
|
||||
|
Loading…
Reference in New Issue
Block a user