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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
package de.cowtipper.cowlection;
import de.cowtipper.cowlection.chesttracker.ChestTracker;
import de.cowtipper.cowlection.command.*;
import de.cowtipper.cowlection.config.CredentialStorage;
import de.cowtipper.cowlection.config.MooConfig;
import de.cowtipper.cowlection.handler.DungeonCache;
import de.cowtipper.cowlection.handler.FriendsHandler;
import de.cowtipper.cowlection.handler.PlayerCache;
import de.cowtipper.cowlection.listener.ChatListener;
import de.cowtipper.cowlection.listener.PlayerListener;
import de.cowtipper.cowlection.partyfinder.Rules;
import de.cowtipper.cowlection.util.ChatHelper;
import de.cowtipper.cowlection.util.VersionChecker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import java.io.File;
@Mod(modid = Cowlection.MODID, name = Cowlection.MODNAME, version = Cowlection.VERSION,
clientSideOnly = true,
updateJSON = "https://raw.githubusercontent.com/cow-mc/Cowlection/master/update.json")
public class Cowlection {
public static final String MODID = "@MODID@";
public static final String VERSION = "@VERSION@";
public static final String MODNAME = "@MODNAME@";
public static final String GITURL = "@GITURL@";
public static KeyBinding[] keyBindings;
private static Cowlection instance;
private File modsDir;
private File modOutDir;
private MooConfig config;
private CredentialStorage moo;
private Rules partyFinderRules;
private FriendsHandler friendsHandler;
private VersionChecker versionChecker;
private ChatHelper chatHelper;
private PlayerCache playerCache;
private DungeonCache dungeonCache;
private ChestTracker chestTracker;
private Logger logger;
@EventHandler
public void preInit(FMLPreInitializationEvent e) {
instance = this;
logger = e.getModLog();
modsDir = e.getSourceFile().getParentFile();
chatHelper = new ChatHelper();
File configDir = new File(e.getModConfigurationDirectory(), MODID + File.separatorChar);
if (!configDir.exists()) {
configDir.mkdirs();
}
friendsHandler = new FriendsHandler(this, new File(configDir, "friends.json"));
moo = new CredentialStorage(new Configuration(new File(configDir, "do-not-share-me-with-other-players.cfg")));
partyFinderRules = new Rules(this, new File(configDir, "partyfinder-rules.json"));
config = new MooConfig(this, new Configuration(new File(configDir, MODID + ".cfg"), "2"));
}
@EventHandler
public void init(FMLInitializationEvent e) {
MinecraftForge.EVENT_BUS.register(new ChatListener(this));
MinecraftForge.EVENT_BUS.register(new PlayerListener(this));
ClientCommandHandler.instance.registerCommand(new MooCommand(this));
ClientCommandHandler.instance.registerCommand(new NumerousCommandsCommand());
ClientCommandHandler.instance.registerCommand(new ReplyCommand());
ClientCommandHandler.instance.registerCommand(new ShrugCommand(this));
for (String tabCompletableNamesCommand : MooConfig.tabCompletableNamesCommands) {
ClientCommandHandler.instance.registerCommand(new TabCompletableCommand(this, tabCompletableNamesCommand));
}
// key bindings
keyBindings = new KeyBinding[2];
keyBindings[0] = new KeyBinding("key.cowlection.moo", Keyboard.KEY_NONE, "key.cowlection.category");
keyBindings[1] = new KeyBinding("key.cowlection.waila", Keyboard.KEY_NONE, "key.cowlection.category");
for (KeyBinding keyBinding : keyBindings) {
ClientRegistry.registerKeyBinding(keyBinding);
}
}
@EventHandler
public void postInit(FMLPostInitializationEvent e) {
versionChecker = new VersionChecker(this);
playerCache = new PlayerCache();
modOutDir = new File(Minecraft.getMinecraft().mcDataDir, Cowlection.MODID.toLowerCase() + "_out");
}
public MooConfig getConfig() {
return config;
}
public CredentialStorage getMoo() {
return moo;
}
public Rules getPartyFinderRules() {
return partyFinderRules;
}
public FriendsHandler getFriendsHandler() {
return friendsHandler;
}
public VersionChecker getVersionChecker() {
return versionChecker;
}
public ChatHelper getChatHelper() {
return chatHelper;
}
public PlayerCache getPlayerCache() {
return playerCache;
}
public DungeonCache getDungeonCache() {
if (dungeonCache == null) {
dungeonCache = new DungeonCache(this);
}
return dungeonCache;
}
public boolean enableChestTracker() {
if (chestTracker == null) {
chestTracker = new ChestTracker(this);
return true;
}
return false;
}
public boolean disableChestTracker() {
if (chestTracker != null) {
chestTracker.clear();
chestTracker = null;
return true;
}
return false;
}
public ChestTracker getChestTracker() {
return chestTracker;
}
public File getModsDirectory() {
return modsDir;
}
public File getModOutDirectory() {
if (!modOutDir.exists() && !modOutDir.mkdirs()) {
// dir didn't exist and couldn't be created
return null;
}
return modOutDir;
}
public Logger getLogger() {
return logger;
}
/**
* Get mod's instance; instead of this method use dependency injection where possible
*/
public static Cowlection getInstance() {
return instance;
}
}
|