Skip to content

Commit e959bff

Browse files
committed
statically added server-updater 3.9.0 by hs-gamer with extensive code review, including statically added its core dependencies
1 parent 4ebbcf8 commit e959bff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2801
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ AUTO-GENERATED FILE, CHANGES SHOULD BE DONE IN ./JPM.java or ./src/main/java/JPM
255255
<version>2.13.0</version>
256256
<scope>compile</scope>
257257
</dependency>
258+
<dependency>
259+
<groupId>org.json</groupId>
260+
<artifactId>json</artifactId>
261+
<version>20250107</version>
262+
<scope>compile</scope>
263+
</dependency>
258264
<dependency>
259265
<groupId>org.nanohttpd</groupId>
260266
<artifactId>nanohttpd</artifactId>

src/main/java/JPM.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public ThisProject(List<String> args) {
7373
implementation("org.tomlj:tomlj:1.0.0");
7474
implementation("com.formdev:flatlaf:2.2");
7575
implementation("org.apache.sshd:sshd-core:2.13.0");
76+
implementation("org.json:json:20250107");
7677

7778
// Minecraft client:
7879
implementation("org.nanohttpd:nanohttpd:2.3.1");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.hsgamer.hscore.collections.map;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* String Hash Map but case-insensitive
8+
*
9+
* @param <V> the type of the value
10+
*/
11+
public class CaseInsensitiveStringHashMap<V> extends CaseInsensitiveStringMap<V> {
12+
13+
public CaseInsensitiveStringHashMap() {
14+
super(new HashMap<>());
15+
}
16+
17+
public CaseInsensitiveStringHashMap(Map<String, ? extends V> map) {
18+
this();
19+
putAll(map);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.hsgamer.hscore.collections.map;
2+
3+
import java.util.LinkedHashMap;
4+
import java.util.Map;
5+
6+
/**
7+
* Linked String Map but case-insensitive
8+
*
9+
* @param <V> the type of the value
10+
*/
11+
public class CaseInsensitiveStringLinkedMap<V> extends CaseInsensitiveStringMap<V> {
12+
13+
public CaseInsensitiveStringLinkedMap() {
14+
super(new LinkedHashMap<>());
15+
}
16+
17+
public CaseInsensitiveStringLinkedMap(Map<String, ? extends V> map) {
18+
this();
19+
putAll(map);
20+
}
21+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package me.hsgamer.hscore.collections.map;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
import java.util.*;
7+
8+
/**
9+
* String Map but case-insensitive
10+
*
11+
* @param <V> the type of the value
12+
*/
13+
public class CaseInsensitiveStringMap<V> implements Map<String, V> {
14+
private final Map<String, V> delegate;
15+
16+
/**
17+
* Create a new case-insensitive map
18+
*
19+
* @param delegate the background map
20+
*/
21+
public CaseInsensitiveStringMap(Map<String, V> delegate) {
22+
this.delegate = delegate;
23+
this.normalize();
24+
}
25+
26+
private String getLowerCase(Object obj) {
27+
return String.valueOf(obj).toLowerCase(Locale.ROOT);
28+
}
29+
30+
private void normalize() {
31+
Map<String, V> linkedMap = new LinkedHashMap<>(delegate);
32+
this.clear();
33+
this.putAll(linkedMap);
34+
linkedMap.clear();
35+
}
36+
37+
@Override
38+
public int size() {
39+
return this.delegate.size();
40+
}
41+
42+
@Override
43+
public boolean isEmpty() {
44+
return this.delegate.isEmpty();
45+
}
46+
47+
@Override
48+
public boolean containsKey(Object o) {
49+
return this.delegate.containsKey(getLowerCase(o));
50+
}
51+
52+
@Override
53+
public boolean containsValue(Object o) {
54+
return this.delegate.containsValue(o);
55+
}
56+
57+
@Override
58+
public V get(Object o) {
59+
return this.delegate.get(getLowerCase(o));
60+
}
61+
62+
@Nullable
63+
@Override
64+
public V put(String s, V v) {
65+
return this.delegate.put(getLowerCase(s), v);
66+
}
67+
68+
@Override
69+
public V remove(Object o) {
70+
return this.delegate.remove(getLowerCase(o));
71+
}
72+
73+
@Override
74+
public void putAll(@NotNull Map<? extends String, ? extends V> map) {
75+
map.forEach(this::put);
76+
}
77+
78+
@Override
79+
public void clear() {
80+
this.delegate.clear();
81+
}
82+
83+
@NotNull
84+
@Override
85+
public Set<String> keySet() {
86+
return this.delegate.keySet();
87+
}
88+
89+
@NotNull
90+
@Override
91+
public Collection<V> values() {
92+
return this.delegate.values();
93+
}
94+
95+
@NotNull
96+
@Override
97+
public Set<Entry<String, V>> entrySet() {
98+
return this.delegate.entrySet();
99+
}
100+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Contains the implementation of {@link java.util.Map}
3+
*/
4+
package me.hsgamer.hscore.collections.map;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.hsgamer.hscore.logger.common;
2+
3+
/**
4+
* The log level
5+
*/
6+
public enum LogLevel {
7+
/**
8+
* A debug message
9+
*/
10+
DEBUG,
11+
/**
12+
* An info message
13+
*/
14+
INFO,
15+
/**
16+
* A warning message
17+
*/
18+
WARN,
19+
/**
20+
* An error message
21+
*/
22+
ERROR
23+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package me.hsgamer.hscore.logger.common;
2+
3+
/**
4+
* The logger
5+
*/
6+
public interface Logger {
7+
/**
8+
* Log a message
9+
*
10+
* @param level the level
11+
* @param message the message
12+
*/
13+
void log(LogLevel level, String message);
14+
15+
/**
16+
* Log an info message
17+
*
18+
* @param message the message
19+
*/
20+
default void log(String message) {
21+
log(LogLevel.INFO, message);
22+
}
23+
24+
/**
25+
* Log a throwable
26+
*
27+
* @param level the level
28+
* @param throwable the throwable
29+
*/
30+
default void log(LogLevel level, Throwable throwable) {
31+
if (throwable == null) {
32+
return;
33+
}
34+
35+
log(level, throwable.getClass().getName() + ": " + throwable.getMessage());
36+
for (StackTraceElement element : throwable.getStackTrace()) {
37+
log(level, " " + element.toString());
38+
}
39+
40+
Throwable cause = throwable.getCause();
41+
if (cause != null) {
42+
log(level, "Caused by: " + cause.getMessage());
43+
log(level, cause);
44+
}
45+
}
46+
47+
/**
48+
* Log a message and a throwable
49+
*
50+
* @param level the level
51+
* @param message the message
52+
* @param throwable the throwable
53+
*/
54+
default void log(LogLevel level, String message, Throwable throwable) {
55+
log(level, message);
56+
log(level, throwable);
57+
}
58+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Contains the base classes for the {@link me.hsgamer.hscore.logger.common.Logger}
3+
*/
4+
package me.hsgamer.hscore.logger.common;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package me.hsgamer.hscore.web;
2+
3+
import java.net.URLConnection;
4+
5+
/**
6+
* The user agent
7+
*/
8+
public final class UserAgent {
9+
/**
10+
* User agent for Firefox
11+
*/
12+
public static final UserAgent FIREFOX = new UserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109) Gecko/20100101 Firefox/112.0");
13+
14+
/**
15+
* User agent for Chrome
16+
*/
17+
public static final UserAgent CHROME = new UserAgent("Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36");
18+
19+
/**
20+
* The agent string
21+
*/
22+
private final String agent;
23+
24+
/**
25+
* Create a new user agent
26+
*
27+
* @param agent the agent string
28+
*/
29+
public UserAgent(String agent) {
30+
this.agent = agent;
31+
}
32+
33+
/**
34+
* Get the agent string
35+
*
36+
* @return the agent string
37+
*/
38+
public String getAgent() {
39+
return agent;
40+
}
41+
42+
/**
43+
* Assign the user agent to the connection
44+
*
45+
* @param <T> the type of the connection
46+
* @param connection the connection
47+
*
48+
* @return the connection for chaining
49+
*/
50+
public <T extends URLConnection> T assignToConnection(T connection) {
51+
connection.setRequestProperty("User-Agent", agent);
52+
return connection;
53+
}
54+
}

0 commit comments

Comments
 (0)