-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
ProfileCommand.java
executable file
·88 lines (81 loc) · 2.71 KB
/
ProfileCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package me.nallar.tickprofiler.minecraft.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.nallar.tickprofiler.Log;
import me.nallar.tickprofiler.minecraft.TickProfiler;
import me.nallar.tickprofiler.minecraft.profiling.EntityTickProfiler;
import me.nallar.tickprofiler.util.TableFormatter;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
public class ProfileCommand extends Command {
public static String name = "profile";
@Override
public String getCommandName() {
return name;
}
@Override
public boolean requireOp() {
return TickProfiler.instance.requireOpForProfileCommand;
}
@Override
public void processCommand(final ICommandSender commandSender, List<String> arguments) {
World world = null;
int time_ = 30;
boolean location = false;
Integer x = null;
Integer z = null;
try {
if ("c".equals(arguments.get(0))) {
location = true;
if (arguments.size() > 2) {
x = Integer.valueOf(arguments.remove(1));
z = Integer.valueOf(arguments.remove(1));
}
}
if (arguments.size() > 1) {
time_ = Integer.valueOf(arguments.get(1));
}
if (arguments.size() > 2) {
world = DimensionManager.getWorld(Integer.valueOf(arguments.get(2)));
} else if (commandSender instanceof Entity) {
world = ((Entity) commandSender).worldObj;
}
if (location && x == null) {
Entity entity = (Entity) commandSender;
x = entity.chunkCoordX;
z = entity.chunkCoordZ;
}
} catch (Exception e) {
sendChat(commandSender, "Usage: /profile [e/(c [chunk x] [chunk z])] [time=30] [dimensionid=all]");
return;
}
final List<World> worlds = new ArrayList<World>();
if (world == null) {
Collections.addAll(worlds, DimensionManager.getWorlds());
} else {
worlds.add(world);
}
final int time = time_;
final EntityTickProfiler entityTickProfiler = EntityTickProfiler.ENTITY_TICK_PROFILER;
if (!entityTickProfiler.startProfiling(new Runnable() {
@Override
public void run() {
sendChat(commandSender, entityTickProfiler.writeData(new TableFormatter(commandSender)).toString());
}
}, location ? ProfilingState.CHUNK : ProfilingState.GLOBAL, time, worlds)) {
sendChat(commandSender, "Someone else is currently profiling.");
}
if (location) {
entityTickProfiler.setLocation(x, z);
}
sendChat(commandSender, "Profiling for " + time + " seconds in " + (world == null ? "all worlds " : Log.name(world)) + (location ? " at " + x + ',' + z : ""));
}
public static enum ProfilingState {
NONE,
GLOBAL,
CHUNK
}
}