66import java .util .Properties ;
77
88public 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 ;
1020
1121 @ SuppressWarnings ("ResultOfMethodCallIgnored" )
1222 public static void runProperties () {
@@ -18,107 +28,80 @@ public static void runProperties() {
1828 }
1929
2030 File propertiesFile = new File (configFolder , "packetfixer.properties" );
21- properties = new Properties ();
31+ Properties properties = new Properties ();
2232
2333 if (!propertiesFile .exists ()) {
2434 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 );
3935 }
4036
4137 properties .load (Files .newInputStream (propertiesFile .toPath ()));
4238
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 );
5551 } catch (IOException e ) {
5652 throw new RuntimeException (e );
5753 }
5854 }
5955
60- private static boolean getUnlimitedPacketSize () {
61- if (properties == null ) runProperties ();
62- return Boolean .parseBoolean (properties .getProperty ("allSizesUnlimited" ));
63- }
64-
6556 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 ;
6858 }
6959
7060 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 ;
7362 }
7463
7564 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 ;
7866 }
7967
8068 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 ;
8370 }
8471
8572 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 ;
8874 }
8975
9076 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 ;
9378 }
9479
9580 public static int getStringSize () {
96- if (properties == null ) runProperties ();
97- return getUnlimitedPacketSize () ? 327670000 : Integer .parseInt (properties .getProperty ("stringSize" ));
81+ return allSizesUnlimited ? 327670000 : stringSize ;
9882 }
9983
10084 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 ;
10386 }
10487
10588 public static int getTimeout () {
106- if (properties == null ) runProperties ();
107- return Integer .parseInt (properties .getProperty ("timeout" ));
89+ return timeout ;
10890 }
10991
11092 public static boolean isForceUnlimitedNbtEnabled () {
111- if (properties == null ) runProperties ();
112- return Boolean .parseBoolean (properties .getProperty ("forceUnlimitedNbtEnabled" ));
93+ return forceUnlimitedNbtEnabled ;
11394 }
11495
115- private static void checkVariable (String variable , String defaultValue ) {
96+ private static String checkVariable (Properties properties , String variable , String defaultValue ) {
11697 if (properties .getProperty (variable ) == null ) {
11798 properties .setProperty (variable , defaultValue );
11899 }
100+
101+ return properties .getProperty (variable );
119102 }
120103
121- private static void save (File propertiesFile ) throws IOException {
104+ private static void save (Properties properties , File propertiesFile ) throws IOException {
122105 properties .store (Files .newOutputStream (propertiesFile .toPath ()),
123106 "Packet Fixer config file.\n " +
124107 "Default values (minecraft default): nbtMaxSize 2097152, packetSize 1048576, decoderSize 8388608 and varInt21Size 3.\n " +
0 commit comments