Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands helper #269

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Commands helper #269

wants to merge 3 commits into from

Conversation

brachy84
Copy link
Member

@brachy84 brachy84 commented Nov 9, 2024

  • adds global commands variable which has helper methods to register client and server commands
  • if commands are registered during postInit they can be reloaded
  • see test in custom/vanilla.groovy

Copy link
Collaborator

@WaitingIdly WaitingIdly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be for documentation only (yippee), but doing something like commands.registerCommand('help') { server, sender, args -> sender.sendMessage('You cannot be helped') }
lets you override commands - and, depending on when things are loaded, might make your custom commands be overridden by preexisting ones.

}

public void registerClientCommand(ICommand command) {
if (FMLCommonHandler.instance().getSide().isServer()) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this print a warning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This way you can just register a command without having to make sure it doent run on server

private boolean serverStarted = false;

public void registerCommand(ICommand command) {
if (GroovyScript.getSandbox().isRunning() && GroovyScript.getSandbox().getCurrentLoader().isReloadable()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this code being required for Commands to work in preInit (if im reading what the reason is correctly) might indicate a deeper issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? I just dont want commands to reload when not registered durin postInit. I dont see any issue

@@ -256,3 +256,7 @@ item('minecraft:golden_apple').setRarity(textformat('-1'))
eventManager.listen(EnderTeleportEvent) { event ->
event.setAttackDamage 19.5f
}

commands.registerCommand('groovy_test') { server, sender, args ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be command.registerCommand after rename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants