File tree 6 files changed +48
-26
lines changed
src/java/com/tamashenning/forgeanalytics
6 files changed +48
-26
lines changed Original file line number Diff line number Diff line change 24
24
25
25
public class AnalyticsClient {
26
26
27
- public boolean UploadModel (AnalyticsModel model ) throws Exception {
27
+ public boolean UploadModel (AnalyticsModel model , boolean isClient ) throws Exception {
28
28
29
29
model .Properties .putAll (ForgeAnalyticsConstants .CustomProperties );
30
30
31
31
Gson g = new Gson ();
32
32
String json = g .toJson (model );
33
33
34
- return this .UploadModel (json );
34
+ return this .UploadModel (json , isClient );
35
35
}
36
36
37
- private boolean UploadModel (String json ) throws Exception {
37
+ private boolean UploadModel (String json , boolean isClient ) throws Exception {
38
38
39
- // Respect snooper settings...
40
- if (!Minecraft .getMinecraft ().isSnooperEnabled ()) {
41
- return false ;
39
+ if (isClient ) {
40
+ // Respect snooper settings...
41
+ if (!Minecraft .getMinecraft ().isSnooperEnabled ()) {
42
+ return false ;
43
+ }
44
+ } else {
45
+ // Respect snooper settings...
46
+ if (!MinecraftServer .getServer ().isSnooperEnabled ()) {
47
+ return false ;
48
+ }
42
49
}
43
50
44
51
System .out .println (json );
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ public void serverLoad(FMLServerStartingEvent e) {
49
49
public void serverStarted (FMLServerStartedEvent e ) {
50
50
AnalyticsClient ac = new AnalyticsClient ();
51
51
try {
52
- ac .UploadModel (ac .CreateServerStartupPing ());
52
+ ac .UploadModel (ac .CreateServerStartupPing (), false );
53
53
} catch (Exception e1 ) {
54
54
// TODO Auto-generated catch block
55
55
e1 .printStackTrace ();
@@ -60,19 +60,7 @@ public void serverStarted(FMLServerStartedEvent e) {
60
60
public void serverStopped (FMLServerStoppedEvent e ) {
61
61
AnalyticsClient ac = new AnalyticsClient ();
62
62
try {
63
- ac .UploadModel (ac .CreateServerStoppedPing ());
64
- } catch (Exception e1 ) {
65
- // TODO Auto-generated catch block
66
- e1 .printStackTrace ();
67
- }
68
- }
69
-
70
- @ SideOnly (Side .CLIENT )
71
- @ EventHandler
72
- public void fmlLoaded (FMLLoadCompleteEvent e ) {
73
- AnalyticsClient ac = new AnalyticsClient ();
74
- try {
75
- ac .UploadModel (ac .CreateClientStartupPing ());
63
+ ac .UploadModel (ac .CreateServerStoppedPing (), false );
76
64
} catch (Exception e1 ) {
77
65
// TODO Auto-generated catch block
78
66
e1 .printStackTrace ();
Original file line number Diff line number Diff line change @@ -39,19 +39,19 @@ public String CreateID() {
39
39
return id ;
40
40
}
41
41
42
- public void StartKeepAliveTimer () {
42
+ public void StartKeepAliveTimer (final boolean isClient ) {
43
43
Timer timer = new Timer ();
44
44
timer .scheduleAtFixedRate (new TimerTask () {
45
45
@ Override
46
46
public void run () {
47
47
try {
48
48
// I'm running locally with no world loaded yet...
49
49
if (Minecraft .getMinecraft ().theWorld == null ) {
50
- ac .UploadModel (ac .CreateClientKeepAlivePing ());
50
+ ac .UploadModel (ac .CreateClientKeepAlivePing (), isClient );
51
51
} else if (!Minecraft .getMinecraft ().theWorld .isRemote ) {
52
- ac .UploadModel (ac .CreateClientKeepAlivePing ());
52
+ ac .UploadModel (ac .CreateClientKeepAlivePing (), isClient );
53
53
} else {
54
- ac .UploadModel (ac .CreateServerKeepAlivePing ());
54
+ ac .UploadModel (ac .CreateServerKeepAlivePing (), isClient );
55
55
}
56
56
} catch (Exception e ) {
57
57
//
@@ -61,5 +61,4 @@ public void run() {
61
61
}
62
62
}, ForgeAnalyticsConstants .KEEPALIVETIME , ForgeAnalyticsConstants .KEEPALIVETIME );
63
63
}
64
-
65
64
}
Original file line number Diff line number Diff line change 1
1
package com .tamashenning .forgeanalytics .proxies ;
2
2
3
+ import com .tamashenning .forgeanalytics .AnalyticsClient ;
4
+ import com .tamashenning .forgeanalytics .client .ForgeAnalyticsSingleton ;
5
+
3
6
import net .minecraftforge .fml .common .event .FMLInitializationEvent ;
4
7
import net .minecraftforge .fml .common .event .FMLPostInitializationEvent ;
5
8
import net .minecraftforge .fml .common .event .FMLPreInitializationEvent ;
@@ -18,5 +21,16 @@ public void init(FMLInitializationEvent e) {
18
21
@ Override
19
22
public void postInit (FMLPostInitializationEvent e ) {
20
23
super .postInit (e );
24
+
25
+ AnalyticsClient ac = new AnalyticsClient ();
26
+ try {
27
+ ac .UploadModel (ac .CreateClientStartupPing (), true );
28
+ } catch (Exception e1 ) {
29
+ // TODO Auto-generated catch block
30
+ e1 .printStackTrace ();
31
+ }
32
+
33
+ ForgeAnalyticsSingleton .getInstance ().StartKeepAliveTimer (true );
34
+
21
35
}
22
36
}
Original file line number Diff line number Diff line change @@ -54,6 +54,6 @@ public void init(FMLInitializationEvent e) {
54
54
}
55
55
56
56
public void postInit (FMLPostInitializationEvent e ) {
57
- ForgeAnalyticsSingleton . getInstance (). StartKeepAliveTimer ();
57
+
58
58
}
59
59
}
Original file line number Diff line number Diff line change 1
1
package com .tamashenning .forgeanalytics .proxies ;
2
2
3
+ import com .tamashenning .forgeanalytics .AnalyticsClient ;
4
+ import com .tamashenning .forgeanalytics .client .ForgeAnalyticsSingleton ;
5
+
3
6
import net .minecraftforge .fml .common .event .FMLInitializationEvent ;
4
7
import net .minecraftforge .fml .common .event .FMLPostInitializationEvent ;
5
8
import net .minecraftforge .fml .common .event .FMLPreInitializationEvent ;
@@ -18,6 +21,17 @@ public void init(FMLInitializationEvent e) {
18
21
@ Override
19
22
public void postInit (FMLPostInitializationEvent e ) {
20
23
super .postInit (e );
24
+
25
+ AnalyticsClient ac = new AnalyticsClient ();
26
+ try {
27
+ ac .UploadModel (ac .CreateClientStartupPing (), false );
28
+ } catch (Exception e1 ) {
29
+ // TODO Auto-generated catch block
30
+ e1 .printStackTrace ();
31
+ }
32
+
33
+ ForgeAnalyticsSingleton .getInstance ().StartKeepAliveTimer (false );
34
+
21
35
}
22
36
23
37
}
You can’t perform that action at this time.
0 commit comments