-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GlobalCommand for cross-platform commands
- Loading branch information
Showing
4 changed files
with
99 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
shared/src/main/java/net/codersky/mcutils/cmd/GlobalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.codersky.mcutils.cmd; | ||
|
||
import net.codersky.mcutils.MCUtils; | ||
import net.codersky.mcutils.crossplatform.MCConsole; | ||
import net.codersky.mcutils.crossplatform.player.MCPlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public abstract class GlobalCommand<P> implements MCCommand<P, MCCommandSender<MCPlayer<?>, MCConsole<?>>> { | ||
|
||
private final MCUtils<P> utils; | ||
private final String name; | ||
private final List<String> aliases; | ||
private final SubCommandHandler<P, MCCommandSender<MCPlayer<?>, MCConsole<?>>> subCmdHandler = new SubCommandHandler<>(); | ||
|
||
public GlobalCommand(MCUtils<P> utils, @NotNull String name, List<String> aliases) { | ||
this.utils = utils; | ||
this.name = name; | ||
this.aliases = aliases; | ||
} | ||
|
||
public GlobalCommand(MCUtils<P> utils, @NotNull String name) { | ||
this(utils, name, List.of()); | ||
} | ||
|
||
public GlobalCommand(MCUtils<P> utils, @NotNull String name, String... aliases) { | ||
this(utils, name, List.of(aliases)); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public @NotNull List<String> getAliases() { | ||
return aliases; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public MCUtils<P> getUtils() { | ||
return utils; | ||
} | ||
|
||
@Override | ||
public @NotNull MCCommand<P, MCCommandSender<MCPlayer<?>, MCConsole<?>>> inject(@NotNull MCCommand<P, MCCommandSender<MCPlayer<?>, MCConsole<?>>>... commands) { | ||
subCmdHandler.inject(commands); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters