6
6
import java .util .Properties ;
7
7
8
8
public class Config {
9
- private static Properties properties = null ;
9
+ private static boolean allSizesUnlimited = true ;
10
+ private static long nbtMaxSize = 2097152 ;
11
+ private static int packetSize = 1048576 ;
12
+ private static int decoderSize = 8388608 ;
13
+ private static int varInt21 = 3 ;
14
+ private static int varInt = 5 ;
15
+ private static int varLong = 10 ;
16
+ private static int stringSize = 32767 ;
17
+ private static int chunkPacketData = 2097152 ;
18
+ private static int timeout = 90 ;
19
+ private static boolean forceUnlimitedNbtEnabled = false ;
10
20
11
21
@ SuppressWarnings ("ResultOfMethodCallIgnored" )
12
22
public static void runProperties () {
@@ -18,107 +28,80 @@ public static void runProperties() {
18
28
}
19
29
20
30
File propertiesFile = new File (configFolder , "packetfixer.properties" );
21
- properties = new Properties ();
31
+ Properties properties = new Properties ();
22
32
23
33
if (!propertiesFile .exists ()) {
24
34
propertiesFile .createNewFile ();
25
-
26
- properties .setProperty ("allSizesUnlimited" , "true" );
27
- properties .setProperty ("nbtMaxSize" , Long .toString (2097152 ));
28
- properties .setProperty ("packetSize" , Integer .toString (1048576 ));
29
- properties .setProperty ("decoderSize" , Integer .toString (8388608 ));
30
- properties .setProperty ("varInt21" , Integer .toString (3 ));
31
- properties .setProperty ("varInt" , Integer .toString (5 ));
32
- properties .setProperty ("varLong" , Integer .toString (10 ));
33
- properties .setProperty ("stringSize" , Integer .toString (32767 ));
34
- checkVariable ("chunkPacketData" , Integer .toString (2097152 ));
35
- properties .setProperty ("timeout" , Integer .toString (90 ));
36
- properties .setProperty ("forceUnlimitedNbtEnabled" , Boolean .toString (false ));
37
-
38
- save (propertiesFile );
39
35
}
40
36
41
37
properties .load (Files .newInputStream (propertiesFile .toPath ()));
42
38
43
- checkVariable ("allSizesUnlimited" , "true" );
44
- checkVariable ("nbtMaxSize" , Long . toString ( 2097152 ));
45
- checkVariable ("packetSize" , Integer .toString (1048576 ));
46
- checkVariable ("decoderSize" , Integer .toString (8388608 ));
47
- checkVariable ("varInt21" , Integer .toString (3 ));
48
- checkVariable ("varInt" , Integer .toString (5 ));
49
- checkVariable ("varLong" , Integer .toString (10 ));
50
- checkVariable ("stringSize" , Integer .toString (32767 ));
51
- checkVariable ("chunkPacketData" , Integer .toString (2097152 ));
52
- checkVariable ("timeout" , Integer .toString (90 ));
53
- checkVariable ("forceUnlimitedNbtEnabled" , Boolean .toString (false ));
54
- save (propertiesFile );
39
+ allSizesUnlimited = Boolean . parseBoolean ( checkVariable (properties , "allSizesUnlimited" , String . valueOf ( allSizesUnlimited )) );
40
+ nbtMaxSize = Long . parseLong ( checkVariable (properties , "nbtMaxSize" , String . valueOf ( nbtMaxSize ) ));
41
+ packetSize = Integer . parseInt ( checkVariable (properties , "packetSize" , Integer .toString (packetSize ) ));
42
+ decoderSize = Integer . parseInt ( checkVariable (properties , "decoderSize" , Integer .toString (decoderSize ) ));
43
+ varInt21 = Integer . parseInt ( checkVariable (properties , "varInt21" , Integer .toString (varInt21 ) ));
44
+ varInt = Integer . parseInt ( checkVariable (properties , "varInt" , Integer .toString (varInt ) ));
45
+ varLong = Integer . parseInt ( checkVariable (properties , "varLong" , Integer .toString (varLong ) ));
46
+ stringSize = Integer . parseInt ( checkVariable (properties , "stringSize" , Integer .toString (stringSize ) ));
47
+ chunkPacketData = Integer . parseInt ( checkVariable (properties , "chunkPacketData" , Integer .toString (chunkPacketData ) ));
48
+ timeout = Integer . parseInt ( checkVariable (properties , "timeout" , Integer .toString (timeout ) ));
49
+ forceUnlimitedNbtEnabled = Boolean . parseBoolean ( checkVariable (properties , "forceUnlimitedNbtEnabled" , Boolean .toString (forceUnlimitedNbtEnabled ) ));
50
+ save (properties , propertiesFile );
55
51
} catch (IOException e ) {
56
52
throw new RuntimeException (e );
57
53
}
58
54
}
59
55
60
- private static boolean getUnlimitedPacketSize () {
61
- if (properties == null ) runProperties ();
62
- return Boolean .parseBoolean (properties .getProperty ("allSizesUnlimited" ));
63
- }
64
-
65
56
public static long getNbtMaxSize () {
66
- if (properties == null ) runProperties ();
67
- return getUnlimitedPacketSize () ? Long .MAX_VALUE : Long .parseLong (properties .getProperty ("nbtMaxSize" ));
57
+ return allSizesUnlimited ? Long .MAX_VALUE : nbtMaxSize ;
68
58
}
69
59
70
60
public static int getPacketSize () {
71
- if (properties == null ) runProperties ();
72
- return getUnlimitedPacketSize () ? Integer .MAX_VALUE : Integer .parseInt (properties .getProperty ("packetSize" ));
61
+ return allSizesUnlimited ? Integer .MAX_VALUE : packetSize ;
73
62
}
74
63
75
64
public static int getDecoderSize () {
76
- if (properties == null ) runProperties ();
77
- return getUnlimitedPacketSize () ? Integer .MAX_VALUE : Integer .parseInt (properties .getProperty ("decoderSize" ));
65
+ return allSizesUnlimited ? Integer .MAX_VALUE : decoderSize ;
78
66
}
79
67
80
68
public static int getVarInt21Size () {
81
- if (properties == null ) runProperties ();
82
- return getUnlimitedPacketSize () ? Integer .MAX_VALUE : Integer .parseInt (properties .getProperty ("varInt21" ));
69
+ return allSizesUnlimited ? Integer .MAX_VALUE : varInt21 ;
83
70
}
84
71
85
72
public static int getVarIntSize () {
86
- if (properties == null ) runProperties ();
87
- return getUnlimitedPacketSize () ? (Integer .MAX_VALUE / 2 - 1 ) : Integer .parseInt (properties .getProperty ("varInt" ));
73
+ return allSizesUnlimited ? (Integer .MAX_VALUE / 2 - 1 ) : varInt ;
88
74
}
89
75
90
76
public static int getVarLong () {
91
- if (properties == null ) runProperties ();
92
- return getUnlimitedPacketSize () ? (Integer .MAX_VALUE / 2 - 1 ) : Integer .parseInt (properties .getProperty ("varLong" ));
77
+ return allSizesUnlimited ? (Integer .MAX_VALUE / 2 - 1 ) : varLong ;
93
78
}
94
79
95
80
public static int getStringSize () {
96
- if (properties == null ) runProperties ();
97
- return getUnlimitedPacketSize () ? 327670000 : Integer .parseInt (properties .getProperty ("stringSize" ));
81
+ return allSizesUnlimited ? 327670000 : stringSize ;
98
82
}
99
83
100
84
public static int getChunkPacketData () {
101
- if (properties == null ) runProperties ();
102
- return getUnlimitedPacketSize () ? Integer .MAX_VALUE : Integer .parseInt (properties .getProperty ("chunkPacketData" ));
85
+ return allSizesUnlimited ? Integer .MAX_VALUE : chunkPacketData ;
103
86
}
104
87
105
88
public static int getTimeout () {
106
- if (properties == null ) runProperties ();
107
- return Integer .parseInt (properties .getProperty ("timeout" ));
89
+ return timeout ;
108
90
}
109
91
110
92
public static boolean isForceUnlimitedNbtEnabled () {
111
- if (properties == null ) runProperties ();
112
- return Boolean .parseBoolean (properties .getProperty ("forceUnlimitedNbtEnabled" ));
93
+ return forceUnlimitedNbtEnabled ;
113
94
}
114
95
115
- private static void checkVariable (String variable , String defaultValue ) {
96
+ private static String checkVariable (Properties properties , String variable , String defaultValue ) {
116
97
if (properties .getProperty (variable ) == null ) {
117
98
properties .setProperty (variable , defaultValue );
118
99
}
100
+
101
+ return properties .getProperty (variable );
119
102
}
120
103
121
- private static void save (File propertiesFile ) throws IOException {
104
+ private static void save (Properties properties , File propertiesFile ) throws IOException {
122
105
properties .store (Files .newOutputStream (propertiesFile .toPath ()),
123
106
"Packet Fixer config file.\n " +
124
107
"Default values (minecraft default): nbtMaxSize 2097152, packetSize 1048576, decoderSize 8388608 and varInt21Size 3.\n " +
0 commit comments