-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathDragonAPICore.java
289 lines (236 loc) · 9.1 KB
/
DragonAPICore.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*******************************************************************************
* @author Reika Kalseki
*
* Copyright 2017
*
* All rights reserved.
* Distribution of the software in any form is only allowed with
* explicit, prior permission from the owner.
******************************************************************************/
package Reika.DragonAPI;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Random;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.PropertyManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeVersion;
import Reika.DragonAPI.Exception.MisuseException;
import Reika.DragonAPI.Exception.RegistrationException;
import Reika.DragonAPI.IO.DirectResourceManager;
import Reika.DragonAPI.Instantiable.Event.Client.GameFinishedLoadingEvent;
import Reika.DragonAPI.Instantiable.IO.ModLogger;
import Reika.DragonAPI.Libraries.Java.ReikaJavaLibrary;
import Reika.DragonAPI.Libraries.Java.ReikaObfuscationHelper;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.FMLInjectionData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class DragonAPICore {
protected DragonAPICore() {throw new MisuseException("The class "+this.getClass()+" cannot be instantiated!");}
public static final Random rand = new Random();
private static final boolean reika = calculateReikasComputer();
public static final String last_API_Version = "@MAJOR_VERSION@"+"@MINOR_VERSION@";
public static boolean debugtest = false;
private static boolean loaded;
private static final long launchTime = ManagementFactory.getRuntimeMXBean().getStartTime();
public static final GameProfile serverProfile = new GameProfile(UUID.fromString("b9a1b954-6651-4bb8-af54-452a4d9fd5a4"), "[SERVER]");
private static GameProfile sessionUser = serverProfile;
private static final String MINFORGE = "required-after:Forge@[10.13.4.1614,);"; //was 1205/1231/1291/1558
public static final String dependencies = MINFORGE+"after:BuildCraft|Energy;after:IC2;after:ThermalExpansion;after:Thaumcraft;"+
"after:powersuits;after:GalacticCraft;after:Mystcraft;after:UniversalElectricity;after:Forestry;after:MagicBees;"+
"after:ExtraBees;after:Natura;after:TConstruct;after:ProjRed|Core;after:bluepower;after:Waila;after:funkylocomotion;after:chisel;"+
"after:ComputerCraft;after:ThermalFoundation;after:CarpentersBlocks;after:AgriCraft;after:MineFactoryReloaded;after:ImmersiveEngineering";
public static final String FORUM_PAGE = "http://www.minecraftforum.net/topic/1969694-";
public static final String GITHUB_PAGE = "https://github.com/ReikaKalseki/Reika_Mods_Issues/issues?q=";
public static final UUID Reika_UUID = UUID.fromString("e5248026-6874-4954-9a02-aa8910d08f31");
public static URL getReikaForumPage() {
try {
return new URL(FORUM_PAGE);
}
catch (MalformedURLException e) {
throw new RegistrationException(DragonAPIInit.instance, "Reika's mods provided a malformed URL for their documentation site!", e);
}
}
public static URL getReikaGithubPage() {
try {
return new URL(GITHUB_PAGE);
}
catch (MalformedURLException e) {
throw new RegistrationException(DragonAPIInit.instance, "Reika's mods provided a malformed URL for their github site!", e);
}
}
public static final boolean hasAllClasses() {
return true;
}
public static File getMinecraftDirectory() {
return (File)FMLInjectionData.data()[6];
}
/*
public static String getMinecraftDirectoryString() {
String s = getMinecraftDirectory().getCanonicalPath();
if (s.endsWith("/.") || s.endsWith("\\.")) {
s = s.substring(0, s.length()-2);
}
s = s.replaceAll("\\\\", "/");
return s;
}
*/
public static File getServerRootFolder() {
File root = getMinecraftDirectory();
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return root;
if (MinecraftServer.getServer() != null) {
if (MinecraftServer.getServer().worldServers.length > 0 && MinecraftServer.getServer().worldServers[0] != null) {
return MinecraftServer.getServer().worldServers[0].getSaveHandler().getWorldDirectory();
}
}
File props = new File("server.properties");
if (!props.exists()) {
props = new File(root, "server.properties");
}
if (props.exists()) {
String name = new PropertyManager(props).getStringProperty("level-name", "world");
return new File(root, name);
}
else {
return root;
}
}
private static boolean calculateReikasComputer() {
try {
String username = System.getProperty("user.name");
boolean win = System.getProperty("os.name").equals("Windows 10");
int cpus = Runtime.getRuntime().availableProcessors();
String cpu = System.getProperty("os.arch");
long diskSize = new File("c:").getTotalSpace();
if (win && "amd64".equals(cpu)) {
if (diskSize == 999524175872L && cpus == 24 && "Reika".equals(username))
return true;
}
return false;
}
catch (Throwable e) {
return false;
}
}
public static boolean isReikasComputer() {
return reika;
}
static {
if (isReikasComputer())
ReikaJavaLibrary.pConsole("DRAGONAPI: Loading on Reika's computer; Dev features enabled.");
//ReikaMathCacher.initalize();
validateForgeVersions();
}
protected static Side getSide() {
return FMLCommonHandler.instance().getEffectiveSide();
}
@SideOnly(Side.CLIENT)
private static GameProfile loadSessionProfile() {
return Minecraft.getMinecraft().getSession().func_148256_e();
}
private static void validateForgeVersions() {
int major = ForgeVersion.majorVersion;
int minor = ForgeVersion.minorVersion;
int rev = ForgeVersion.revisionVersion;
int build = ForgeVersion.buildVersion;
int recbuild = 1291;
if (build < recbuild) {
log("The version of Forge you are using is compatible but not recommended.");
log(String.format("Consider updating to at least %d.%d.%d.%d.", major, minor, rev, recbuild));
}
}
public static boolean isOnActualServer() {
return getSide() == Side.SERVER && FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer();
}
@SideOnly(Side.CLIENT)
public static boolean isSinglePlayerFromClient() {
return Minecraft.getMinecraft().isSingleplayer();
}
public static boolean isSinglePlayer() {
return getSide() == Side.SERVER && !FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer();
}
public static boolean isRemoteSinglePlayer() {
return isOnActualServer() && MinecraftServer.getServer().getConfigurationManager().getMaxPlayers() == 1;
}
public static void debugPrint(Object o) {
ReikaJavaLibrary.pConsole(o);
if (!ReikaObfuscationHelper.isDeObfEnvironment())
Thread.dumpStack();
}
public static void debug(Object s) {
ModLogger log = DragonAPIInit.instance == null ? null : DragonAPIInit.instance.getModLogger();
if (log == null)
ReikaJavaLibrary.pConsole("DRAGONAPI DEBUG: "+s);
else
log.debug(s);
}
public static void log(Object s) {
ModLogger log = DragonAPIInit.instance == null ? null : DragonAPIInit.instance.getModLogger();
if (log == null)
ReikaJavaLibrary.pConsole("DRAGONAPI: "+s);
else
log.log(s);
}
public static void logError(Object s) {
ModLogger log = DragonAPIInit.instance == null ? null : DragonAPIInit.instance.getModLogger();
if (log == null)
ReikaJavaLibrary.pConsole("DRAGONAPI ERROR: "+s);
else
log.logError(s);
}
public static void logError(Object o, Side side) {
if (FMLCommonHandler.instance().getEffectiveSide() == side)
logError(o);
}
public static class DragonAPILoadWatcher {
public static final DragonAPILoadWatcher instance = new DragonAPILoadWatcher();
private DragonAPILoadWatcher() {
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void load(GameFinishedLoadingEvent evt) {
loaded = true;
sessionUser = loadSessionProfile();
}
}
public static boolean hasGameLoaded() {
return loaded;
}
public static void setGameLoaded() {
loaded = true;
}
public static long getLaunchTime() {
return launchTime;
}
public static GameProfile getLaunchingPlayer() {
return sessionUser;
}
public static int getSystemTimeAsInt() {
long t = System.currentTimeMillis();
return (int)((t%(Integer.MAX_VALUE+1L)+Integer.MAX_VALUE)%(Integer.MAX_VALUE+1));
}
public static void openURL(String url) throws Exception {
Class oclass = Class.forName("java.awt.Desktop");
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]);
oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(url)});
}
public static ResourceLocation getDirectResource(String path) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
return loadDirectResource(path);
else
return new ResourceLocation("custom_path", path);
}
@SideOnly(Side.CLIENT)
private static ResourceLocation loadDirectResource(String path) {
return DirectResourceManager.getResource(path);
}
}