Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Nullchecking addressing issue 23 #33

Draft
wants to merge 6 commits into
base: 1.19
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unnecessary commentary
  • Loading branch information
AntonBoch1244 authored Apr 20, 2023
commit 66fd69ab47acbf7b6101c06cb1594ded055f67f0
20 changes: 3 additions & 17 deletions src/main/java/org/orecruncher/dsurround/processing/Handlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ protected static PlayerEntity getPlayer() {
}

private void register(final ClientHandler handler) {
// null check
if (this.effectHandlers != null || handler != null) {
if (this.effectHandlers != null && handler != null) {
this.effectHandlers.add(handler);
LOGGER.debug("Registered handler [%s]", handler.getClass().getName());
}
Expand All @@ -71,10 +70,8 @@ private void onConnect(ClientPlayNetworkHandler handler, PacketSender sender, Mi
if (!isConnected) {
isConnected = true;

// null check
if (this.effectHandlers != null) {
for (final ClientHandler h : this.effectHandlers) {
// null check
if (h == null) continue;

h.connect0();
Expand All @@ -86,13 +83,11 @@ private void onConnect(ClientPlayNetworkHandler handler, PacketSender sender, Mi
}

private void onDisconnect(ClientPlayNetworkHandler handler, MinecraftClient client) {
// null check
// No client or network handler == not connected
if (handler == null || client == null) return;

if (this.effectHandlers != null) {
for (final ClientHandler h : this.effectHandlers) {
// null check
if (h == null) continue;
h.disconnect0();
}
Expand All @@ -110,10 +105,10 @@ protected boolean doTick() {
protected boolean playerChunkLoaded() {
var player = GameUtils.getPlayer();

// null check before it crash game
// before it crash game
if (player != null) {
var pos = player.getBlockPos();
// null check before it crash game also
// before it crash game also
if (pos != null) {
return WorldUtils.isChunkLoaded(player.getEntityWorld(), pos);
}
Expand All @@ -124,7 +119,6 @@ protected boolean playerChunkLoaded() {
}

public void onTick(MinecraftClient client) {
// null check
// reduces crashes. #Investigate
if (client == null) return;

Expand All @@ -134,15 +128,12 @@ public void onTick(MinecraftClient client) {
if (!doTick())
return;

// null check
if (this.handlerTimer != null) {
this.handlerTimer.begin();
final long tick = TickCounter.getTickCount();

// null check
if (this.effectHandlers != null) {
for (final ClientHandler handler : this.effectHandlers) {
// null check
// reduces crashes, continue if handler is null
if (handler == null) continue;

Expand All @@ -159,7 +150,6 @@ public void onTick(MinecraftClient client) {
private void handleStartupSound() {
var client = GameUtils.getMC();

// null check
if (client == null) return;

if (client.getOverlay() != null)
Expand All @@ -176,24 +166,20 @@ private void handleStartupSound() {
.create(id)
.build()
.createAsAdditional();
// null check
if (sound == null) return;
client.getSoundManager().play(sound);
});
}

public void gatherDiagnostics(Collection<String> left, Collection<String> right, Collection<TimerEMA> timers) {
// null check
// null handlerTimer useless
// null timers lead crash
if (timers == null || this.handlerTimer == null) return;

timers.add(this.handlerTimer);

// null check
if (this.effectHandlers != null) {
this.effectHandlers.forEach(h -> {
// null check
if (h == null) return;

h.gatherDiagnostics(left, right, timers);
Expand Down