added profile command

This commit is contained in:
gnembon committed 2020-02-06 09:33:46 -04:00
1 parent e6a49467c4
commit 85a34fdefa
4 files changed
+44 -14

No files matched your search

+2 -12
View File
@@ -5,18 +5,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import carpet.commands.CameraModeCommand;
import carpet.commands.CounterCommand;
import carpet.commands.DistanceCommand;
import carpet.commands.DrawCommand;
import carpet.commands.InfoCommand;
import carpet.commands.LogCommand;
import carpet.commands.MobAICommand;
import carpet.commands.PerimeterInfoCommand;
import carpet.commands.PlayerCommand;
import carpet.commands.ScriptCommand;
import carpet.commands.SpawnCommand;
import carpet.commands.TickCommand;
import carpet.commands.*;
import carpet.helpers.TickSpeed;
import carpet.logging.LoggerRegistry;
import carpet.script.CarpetScriptServer;
@@ -89,6 +78,7 @@ public class CarpetServer // static for now - easier to handle all around the co
public static void registerCarpetCommands(CommandDispatcher<ServerCommandSource> dispatcher)
{
TickCommand.register(dispatcher);
ProfileCommand.register(dispatcher);
CounterCommand.register(dispatcher);
LogCommand.register(dispatcher);
SpawnCommand.register(dispatcher);
+7
View File
@@ -231,6 +231,13 @@ public class CarpetSettings
@Rule(desc = "Enables /tick command to control game clocks", category = COMMAND)
public static String commandTick = "true";
@Rule(
desc = "Enables /profile command to monitor game performance",
extra = "subset of /tick command capabilities",
category = COMMAND
)
public static String commandProfile = "true";
@Rule(desc = "Enables /log command to monitor events via chat and overlays", category = COMMAND)
public static String commandLog = "true";
@@ -0,0 +1,33 @@
package carpet.commands;
import carpet.CarpetSettings;
import carpet.settings.SettingsManager;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.server.command.ServerCommandSource;
import static carpet.commands.TickCommand.healthEntities;
import static carpet.commands.TickCommand.healthReport;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal;
public class ProfileCommand
{
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("profile").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandProfile)).
executes( (c) -> healthReport(c.getSource(), 100)).
then(literal("health").
executes( (c) -> healthReport(c.getSource(), 100)).
then(argument("ticks", integer(20,24000)).
executes( (c) -> healthReport(c.getSource(), getInteger(c, "ticks"))))).
then(literal("entities").
executes((c) -> healthEntities(c.getSource(), 100)).
then(argument("ticks", integer(20,24000)).
executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks")))));
dispatcher.register(literalargumentbuilder);
}
}
@@ -129,13 +129,13 @@ public class TickCommand
return 1;
}
private static int healthReport(ServerCommandSource source, int ticks)
public static int healthReport(ServerCommandSource source, int ticks)
{
CarpetProfiler.prepare_tick_report(source, ticks);
return 1;
}
private static int healthEntities(ServerCommandSource source, int ticks)
public static int healthEntities(ServerCommandSource source, int ticks)
{
CarpetProfiler.prepare_entity_report(source, ticks);
return 1;