forked from maruohon/servux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,496 additions
and
421 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
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
30 changes: 24 additions & 6 deletions
30
src/main/java/fi/dy/masa/servux/commands/CommandProvider.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 |
---|---|---|
@@ -1,22 +1,40 @@ | ||
package fi.dy.masa.servux.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import com.mojang.brigadier.CommandDispatcher; | ||
import net.minecraft.command.CommandRegistryAccess; | ||
import net.minecraft.server.command.CommandManager; | ||
import net.minecraft.server.command.ServerCommandSource; | ||
import fi.dy.masa.servux.interfaces.IServerCommand; | ||
|
||
public class CommandProvider | ||
public class CommandProvider implements ICommandProvider | ||
{ | ||
private static final CommandProvider INSTANCE = new CommandProvider(); | ||
public static CommandProvider getInstance() { return INSTANCE; } | ||
private final List<IServerCommand> commands = new ArrayList<>(); | ||
public static ICommandProvider getInstance() { return INSTANCE; } | ||
|
||
/** | ||
* The idea here is to eventually create a more Robust Command Provider, using an interface | ||
*/ | ||
@Override | ||
public void registerCommand(IServerCommand command) | ||
{ | ||
if (!this.commands.contains(command)) | ||
{ | ||
this.commands.add(command); | ||
} | ||
} | ||
|
||
@Override | ||
public void unregisterCommand(IServerCommand command) | ||
{ | ||
this.commands.remove(command); | ||
} | ||
|
||
@ApiStatus.Internal | ||
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, | ||
CommandRegistryAccess registryAccess, | ||
CommandManager.RegistrationEnvironment environment) | ||
{ | ||
ServuxCommand.register(dispatcher); | ||
this.commands.forEach((command) -> command.register(dispatcher, registryAccess, environment)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/fi/dy/masa/servux/commands/ICommandProvider.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,9 @@ | ||
package fi.dy.masa.servux.commands; | ||
|
||
import fi.dy.masa.servux.interfaces.IServerCommand; | ||
|
||
public interface ICommandProvider | ||
{ | ||
void registerCommand(IServerCommand command); | ||
void unregisterCommand(IServerCommand command); | ||
} |
Oops, something went wrong.