aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/galacticgreg/command/ProfilingCommand.java
blob: 91805265dcd176fc30cf1abba7a6330324780290 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
package galacticgreg.command;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import galacticgreg.GalacticGreg;
import galacticgreg.api.ModContainer;
import galacticgreg.api.ModDimensionDef;
import galacticgreg.registry.GalacticGregRegistry;

/**
 * Ingame command to get the average oregen time(s) for the active dimensions Doesn't need to be changed when adding new
 * planets/mods
 *
 */
public class ProfilingCommand implements ICommand {

    private List<String> aliases;

    public ProfilingCommand() {
        this.aliases = new ArrayList<>();
        this.aliases.add("ggregprofiler");
    }

    @Override
    public String getCommandName() {
        return "ggregprofiler";
    }

    @Override
    public String getCommandUsage(ICommandSender pCommandSender) {
        return "ggregprofiler";
    }

    @Override
    public List<String> getCommandAliases() {
        return this.aliases;
    }

    @Override
    public void processCommand(ICommandSender pCommandSender, String[] pArgs) {
        pCommandSender.addChatMessage(new ChatComponentText("Average OreGen times:"));

        for (ModContainer mc : GalacticGregRegistry.getModContainers()) {
            String tModName = mc.getModName();
            for (ModDimensionDef mdd : mc.getDimensionList()) {
                long tTime = GalacticGreg.Profiler.GetAverageTime(mdd);
                String tInfo;
                if (tTime == -1) tInfo = "N/A";
                else tInfo = String.format("%d ms", tTime);
                pCommandSender.addChatMessage(
                    new ChatComponentText(
                        String.format("%s (%s): %s", mdd.getDimIdentifier(), mdd.getDimensionName(), tInfo)));
            }
        }
    }

    @Override
    public boolean canCommandSenderUseCommand(ICommandSender pCommandSender) {
        if (FMLCommonHandler.instance()
            .getEffectiveSide() == Side.SERVER
            && !FMLCommonHandler.instance()
                .getMinecraftServerInstance()
                .isDedicatedServer())
            return true;

        if (pCommandSender instanceof EntityPlayerMP) {
            EntityPlayerMP tEP = (EntityPlayerMP) pCommandSender;
            return MinecraftServer.getServer()
                .getConfigurationManager()
                .func_152596_g(tEP.getGameProfile());
        }
        return false;
    }

    @Override
    public int compareTo(Object o) {
        return 0;
    }

    @SuppressWarnings("rawtypes")
    @Override
    public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) {
        return null;
    }

    @Override
    public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
        return false;
    }
}