Skip to content

Commit 8f48abb

Browse files
committed
Added checkstyle and editorconfig
1 parent 605373f commit 8f48abb

10 files changed

Lines changed: 523 additions & 109 deletions

File tree

.editorconfig

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{java,xml,gradle}]
10+
tab_width = 4
11+
indent_size = 4
12+
13+
[*.{json,yml,yaml}]
14+
tab_width = 2
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false
19+
20+
[*.java]
21+
max_line_length = off
22+
ij_java_imports_layout = *, |, javax.**, java.**, |, $*
23+
ij_java_doc_enable_formatting = true
24+
ij_java_doc_use_throws_not_exception_tag = true
25+
26+
# Checkstyle: AnnotationLocation
27+
ij_java_class_annotation_wrap = split_into_lines
28+
ij_java_field_annotation_wrap = split_into_lines
29+
ij_java_method_annotation_wrap = split_into_lines
30+
31+
# Checkstyle: AvoidStarImport
32+
ij_java_use_single_class_imports = true
33+
ij_java_class_count_to_use_import_on_demand = 999999
34+
ij_java_names_count_to_use_import_on_demand = 3
35+
ij_java_packages_to_use_import_on_demand =
36+
37+
# Checkstyle: EmptyForInitializerPad
38+
ij_java_space_before_for_semicolon = false
39+
40+
# Checkstyle: EmptyLineSeparator
41+
ij_java_blank_lines_after_package = 1
42+
ij_java_blank_lines_after_imports = 1
43+
ij_java_blank_lines_around_class = 1
44+
ij_java_blank_lines_around_initializer = 1
45+
ij_java_blank_lines_around_method = 1
46+
ij_java_blank_lines_around_method_in_interface = 1
47+
ij_java_blank_lines_around_field = 0
48+
ij_java_blank_lines_around_field_in_interface = 0
49+
ij_java_blank_lines_around_field_with_annotations = 0
50+
ij_java_keep_blank_lines_before_right_brace = 1
51+
ij_java_keep_blank_lines_in_code = 1
52+
ij_java_keep_blank_lines_in_declarations = 1
53+
54+
# Checkstyle: FinalLocalVariable
55+
ij_java_generate_final_locals = true
56+
ij_java_generate_final_parameters = true
57+
58+
# Checkstyle: GenericWhitespace
59+
ij_java_spaces_within_angle_brackets = false
60+
ij_java_space_before_opening_angle_bracket_in_type_parameter = false
61+
ij_java_space_after_closing_angle_bracket_in_type_argument = false
62+
ij_java_spaces_around_type_bounds_in_type_parameters = true
63+
64+
# Checkstyle: JavadocMissingLeadingAsterisk
65+
ij_java_doc_enable_leading_asterisks = true
66+
67+
# Checkstyle: LeftCurly
68+
ij_java_block_brace_style = end_of_line
69+
ij_java_class_brace_style = end_of_line
70+
ij_java_method_brace_style = end_of_line
71+
ij_java_lambda_brace_style = end_of_line
72+
73+
# Checkstyle: MethodParamPad
74+
ij_java_space_before_method_call_parentheses = false
75+
ij_java_space_before_method_parentheses = false
76+
77+
# Checkstyle: NeedBraces
78+
ij_java_if_brace_force = always
79+
ij_java_for_brace_force = always
80+
ij_java_while_brace_force = always
81+
ij_java_do_while_brace_force = always
82+
83+
# Checkstyle: NoWhitespaceAfter / NoWhitespaceBefore
84+
ij_java_spaces_around_unary_operator = false
85+
86+
# Checkstyle: NoWhitespaceBefore
87+
ij_java_space_before_comma = false
88+
89+
# Checkstyle: OneStatementPerLine
90+
ij_java_keep_multiple_expressions_in_one_line = false
91+
92+
# Checkstyle: OperatorWrap
93+
ij_java_binary_operation_sign_on_next_line = true
94+
ij_java_ternary_operation_signs_on_next_line = true
95+
96+
# Checkstyle: ParenPad
97+
ij_java_spaces_within_method_call_parentheses = false
98+
ij_java_spaces_within_method_parentheses = false
99+
ij_java_spaces_within_parentheses = false
100+
ij_java_spaces_within_if_parentheses = false
101+
ij_java_spaces_within_for_parentheses = false
102+
ij_java_spaces_within_while_parentheses = false
103+
ij_java_spaces_within_switch_parentheses = false
104+
ij_java_spaces_within_catch_parentheses = false
105+
ij_java_spaces_within_synchronized_parentheses = false
106+
ij_java_spaces_within_try_parentheses = false
107+
108+
# Checkstyle: RequireEmptyLineBeforeBlockTagGroup
109+
ij_java_doc_add_blank_line_after_description = true
110+
111+
# Checkstyle: RightCurly
112+
ij_java_else_on_new_line = false
113+
ij_java_catch_on_new_line = false
114+
ij_java_finally_on_new_line = false
115+
ij_java_while_on_new_line = false
116+
117+
# Checkstyle: SeparatorWrap
118+
ij_java_method_call_chain_wrap = normal
119+
ij_java_wrap_first_method_in_call_chain = false
120+
121+
# Checkstyle: TypecastParenPad
122+
ij_java_spaces_within_cast_parentheses = false
123+
124+
# Checkstyle: WhitespaceAfter
125+
ij_java_space_after_type_cast = true
126+
ij_java_space_after_for_semicolon = true
127+
ij_java_space_after_comma = true
128+
ij_java_space_after_comma_in_type_arguments = true
129+
130+
# Checkstyle: WhitespaceAround
131+
ij_java_space_before_if_parentheses = true
132+
ij_java_space_before_for_parentheses = true
133+
ij_java_space_before_while_parentheses = true
134+
ij_java_space_before_switch_parentheses = true
135+
ij_java_space_before_catch_parentheses = true
136+
ij_java_space_before_synchronized_parentheses = true
137+
ij_java_space_before_try_parentheses = true
138+
ij_java_spaces_around_additive_operators = true
139+
ij_java_spaces_around_assignment_operators = true
140+
ij_java_spaces_around_bitwise_operators = true
141+
ij_java_spaces_around_equality_operators = true
142+
ij_java_spaces_around_lambda_arrow = true
143+
ij_java_spaces_around_logical_operators = true
144+
ij_java_spaces_around_multiplicative_operators = true
145+
ij_java_spaces_around_relational_operators = true
146+
ij_java_spaces_around_shift_operators = true
147+
ij_java_space_before_quest = true
148+
ij_java_space_after_quest = true
149+
ij_java_space_before_colon = true
150+
ij_java_space_after_colon = true
151+
ij_java_space_before_colon_in_foreach = true
152+
ij_java_space_before_class_left_brace = true
153+
ij_java_space_before_method_left_brace = true
154+
ij_java_space_before_if_left_brace = true
155+
ij_java_space_before_for_left_brace = true
156+
ij_java_space_before_while_left_brace = true
157+
ij_java_space_before_switch_left_brace = true
158+
ij_java_space_before_try_left_brace = true
159+
ij_java_space_before_catch_left_brace = true
160+
ij_java_space_before_else_left_brace = true
161+
ij_java_space_before_finally_left_brace = true
162+
ij_java_space_before_do_left_brace = true
163+
ij_java_space_before_synchronized_left_brace = true

Agent/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id "java"
33
id "base.base-conventions"
4+
id "base.checkstyle"
45
id "base.application-conventions"
56
id "net.lenni0451.jar-transformer" version "1.1.0"
67
}

Agent/src/main/java/net/lenni0451/authhook/Agent.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import java.lang.instrument.Instrumentation;
2121
import java.util.Map;
2222

23-
public class Agent {
23+
public final class Agent {
24+
25+
private Agent() {
26+
}
2427

2528
public static void agentmain(final String args, final Instrumentation instrumentation) {
2629
hook(instrumentation);
@@ -32,15 +35,15 @@ public static void premain(final String args, final Instrumentation instrumentat
3235

3336
private static void hook(final Instrumentation instrumentation) {
3437
try {
35-
Map<String, String> config = Config.load();
38+
final Map<String, String> config = Config.load();
3639
if (config.get(Config.SECRET_KEY).contains(" ")) {
3740
System.err.println("Please set a valid secret key in the auth_hook.properties file");
3841
System.err.println("It is automatically generated by ViaProxy if you have the AuthHook plugin installed");
3942
System.exit(-1);
4043
}
4144

42-
instrumentation.addTransformer(new URLRedirector(config), true);
43-
} catch (Throwable t) {
45+
instrumentation.addTransformer(new UrlRedirector(config), true);
46+
} catch (final Throwable t) {
4447
System.err.println("An error occurred while starting AuthHook");
4548
t.printStackTrace();
4649
System.exit(-1);

Agent/src/main/java/net/lenni0451/authhook/Config.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,26 @@
2424
import java.util.Map;
2525
import java.util.Scanner;
2626

27-
public class Config {
27+
public final class Config {
2828

2929
private static final File PATH = new File("auth_hook.properties");
3030
public static final String TARGET_ADDRESS = "target_address";
3131
public static final String SECRET_KEY = "secret_key";
3232

33-
private static Map<String, String> getDefaults() {
34-
Map<String, String> def = new LinkedHashMap<>();
35-
def.put(TARGET_ADDRESS, "http://localhost:8080");
36-
def.put(SECRET_KEY, "paste secret key from ViaProxy here");
37-
return def;
33+
private Config() {
3834
}
3935

4036
public static Map<String, String> load() throws IOException {
41-
Map<String, String> config = getDefaults();
37+
final Map<String, String> config = getDefaults();
4238
if (PATH.exists()) {
4339
try (Scanner scanner = new Scanner(PATH)) {
4440
while (scanner.hasNextLine()) {
45-
String line = scanner.nextLine();
46-
if (line.startsWith("#")) continue;
41+
final String line = scanner.nextLine();
42+
if (line.startsWith("#")) {
43+
continue;
44+
}
4745
if (line.contains("=")) {
48-
String[] split = line.split("=", 2);
46+
final String[] split = line.split("=", 2);
4947
config.put(split[0], split[1]);
5048
}
5149
}
@@ -65,4 +63,11 @@ public static void save(final Map<String, String> config) throws IOException {
6563
}
6664
}
6765

66+
private static Map<String, String> getDefaults() {
67+
final Map<String, String> def = new LinkedHashMap<>();
68+
def.put(TARGET_ADDRESS, "http://localhost:8080");
69+
def.put(SECRET_KEY, "paste secret key from ViaProxy here");
70+
return def;
71+
}
72+
6873
}

Agent/src/main/java/net/lenni0451/authhook/URLRedirector.java renamed to Agent/src/main/java/net/lenni0451/authhook/UrlRedirector.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,37 @@
2828
import java.security.ProtectionDomain;
2929
import java.util.Map;
3030

31-
public class URLRedirector implements ClassFileTransformer {
31+
public class UrlRedirector implements ClassFileTransformer {
3232

3333
private static final String URL = "https://sessionserver.mojang.com";
3434

3535
private final String targetAddress;
3636
private final String secretKey;
3737

38-
public URLRedirector(final Map<String, String> config) {
39-
this.targetAddress = this.formatURL(config.get(Config.TARGET_ADDRESS));
38+
public UrlRedirector(final Map<String, String> config) {
39+
this.targetAddress = this.formatUrl(config.get(Config.TARGET_ADDRESS));
4040
this.secretKey = config.get(Config.SECRET_KEY);
4141
}
4242

43-
private String formatURL(String url) {
43+
private String formatUrl(String url) {
4444
if (!url.startsWith("http://") && !url.startsWith("https://")) {
4545
throw new IllegalArgumentException("Invalid URL (missing protocol): " + url);
4646
}
47-
while (url.endsWith("/")) url = url.substring(0, url.length() - 1);
47+
while (url.endsWith("/")) {
48+
url = url.substring(0, url.length() - 1);
49+
}
4850
return url;
4951
}
5052

5153
@Override
52-
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
54+
public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) {
5355
try {
54-
ClassNode node = this.read(classfileBuffer);
56+
final ClassNode node = this.read(classfileBuffer);
5557
boolean modified = false;
5658
for (MethodNode method : node.methods) {
5759
for (AbstractInsnNode insn : method.instructions) {
5860
if (insn instanceof LdcInsnNode && ((LdcInsnNode) insn).cst instanceof String) {
59-
LdcInsnNode ldc = (LdcInsnNode) insn;
61+
final LdcInsnNode ldc = (LdcInsnNode) insn;
6062
String str = (String) ldc.cst;
6163
if (str.startsWith(URL)) {
6264
str = str.substring(URL.length());
@@ -70,20 +72,20 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
7072
}
7173
}
7274
return modified ? this.write(node) : null;
73-
} catch (Throwable ignored) {
75+
} catch (final Throwable ignored) {
7476
}
7577
return null;
7678
}
7779

7880
private ClassNode read(final byte[] bytes) {
79-
ClassNode node = new ClassNode();
80-
ClassReader reader = new ClassReader(bytes);
81+
final ClassNode node = new ClassNode();
82+
final ClassReader reader = new ClassReader(bytes);
8183
reader.accept(node, ClassReader.EXPAND_FRAMES);
8284
return node;
8385
}
8486

8587
private byte[] write(final ClassNode node) {
86-
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
88+
final ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
8789
node.accept(writer);
8890
return writer.toByteArray();
8991
}

0 commit comments

Comments
 (0)