mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Lazy command initialization
This commit is contained in:
		@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user