Problems with running commands
PutridNonsense opened this issue ยท 2 comments
Issue description
I want to run a command using CraftTweaker. I've tried using other commands, single quotes, double quotes, no quotes, even, but none of them seem to work. According to the docs, it seems easy enough (MCServer.executeCommand(command as string) as int
) but doing what the docs said has led me to write this. Please, all I want is funny dwarves
Steps to reproduce
No response
Script used
https://gist.github.com/CLMagnus/a6a6b1918f40a5e1fe4c1e96c32f7ed5
The crafttweaker.log file
https://gist.github.com/CLMagnus/0f96f4a1330be5bf1c81904d7cd69f06
Minecraft version
1.16
Forge version
36.2.4
CraftTweaker version
7.1.2.423
Other relevant information
Tested on a Minecraft instance with only Pehkui and CraftTweaker
Pehkui-2.4.0+1.16.5-forge.jar
The latest.log file
https://gist.github.com/CLMagnus/11e73db3ed8a03a47b198f8ab9a3be81
Thanks bro. Appreciate your help.
Edit: The above script doesn't work, however this one works:
import crafttweaker.api.events.CTEventManager;
import crafttweaker.api.event.entity.player.MCPlayerLoggedInEvent;
CTEventManager.register<crafttweaker.api.event.entity.player.MCPlayerLoggedInEvent>((event) => {
var player = event.getPlayer();
if player.getWorld().isRemote() {
return; // we only want this to run on the server, so we return early on the client.
}
var server = player.getWorld().asServerWorld().server;
server.executeCommand("scale set pehkui:height 0.75 " + player.getName());
server.executeCommand("scale set pehkui:width 0.75 " + player.getName());
});
The issue is that you are calling the method as if it was a static method, you need an instance of MCServer to call it, which can be done like so:
server.executeCommand("scale set pehkui:height 0.75 @a");
server.executeCommand("scale set pehkui:width 0.75 @a");
But, you won't have a server instance when scripts load, you would only have it in an event, like the entity join world event for example:
import crafttweaker.api.events.CTEventManager;
import crafttweaker.api.event.entity.MCEntityJoinWorldEvent;
CTEventManager.register<crafttweaker.api.event.entity.MCEntityJoinWorldEvent>((event) => {
if event.world.isRemote() {
return; // we only want this to run on the server, so we return early on the client.
}
server.executeCommand("scale set pehkui:height 0.75 @a");
server.executeCommand("scale set pehkui:width 0.75 @a");
});