Skip to content

Commit 27a80d2

Browse files
committed
Fix some potential bugs and some semantics
Signed-off-by: Nova <[email protected]>
1 parent 98d7f39 commit 27a80d2

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/main/java/com/hackclub/hccore/listeners/ServerListPingListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public ServerListPingListener(HCCorePlugin plugin) {
1212
}
1313
@EventHandler
1414
public void serverListPing(PaperServerListPingEvent e) {
15-
e.setServerIcon(plugin.serverIcon);
15+
if (plugin.serverIcon != null) {
16+
e.setServerIcon(plugin.serverIcon);
17+
}
1618
}
1719
}

src/main/java/com/hackclub/hccore/tasks/IconTask.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818
public class IconTask implements Runnable {
1919
private final HCCorePlugin plugin;
20+
private final HttpClient client;
2021
public IconTask(HCCorePlugin plugin) {
2122
this.plugin = plugin;
23+
this.client = HttpClient.newHttpClient();
2224
}
2325

2426
@Override
2527
public void run() {
2628
Logger logger = plugin.getLogger();
2729

28-
HttpClient client = HttpClient.newHttpClient();
2930
// get the icon url from Shrimp Shuffler
3031
HttpRequest ssRequest = HttpRequest.newBuilder()
3132
.uri(URI.create("https://shrimp-shuffler.a.hackclub.dev/api/current"))
@@ -74,20 +75,20 @@ public void run() {
7475
ByteArrayInputStream in = new ByteArrayInputStream(cdnResponse.body());
7576
image = ImageIO.read(in);
7677
} catch (IOException e) {
77-
logger.severe("Failed to load the current icon from the file!");
78+
logger.severe("Failed to load the current icon from the CDN response!");
7879
logger.severe(e.getMessage());
7980
return;
8081
}
8182
if (image == null) {
82-
logger.severe("Failed to load the current icon from the file!");
83+
logger.severe("Failed to load the current icon from the CDN response!");
8384
return;
8485
}
8586
BufferedImage serverIcon = resizeToIcon(image);
8687
Bukkit.getScheduler().runTask(plugin, () -> {
8788
try {
8889
plugin.serverIcon = Bukkit.loadServerIcon(serverIcon);
8990
} catch (Exception e) {
90-
logger.severe("Failed to load the current icon from the file!");
91+
logger.severe("Failed to cache the current icon!");
9192
logger.severe(e.getMessage());
9293
}
9394
});

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ claim-stickers-url: "https://example.com/claim-stickers"
33
settings:
44
# Time in seconds after which a player will be automatically set to AFK
55
auto-afk-time: 600
6-
# Time in seconds that a request is made to the Shrimp Shuffler API to change the server icon.
6+
# Time in seconds between requests are made to the Shrimp Shuffler API to change the server icon.
77
icon-change-time: 600
88
spawn-command:
99
# Radius extending from the world spawn in which the command can be used

0 commit comments

Comments
 (0)