Skip to content

Commit

Permalink
Fix NPE when capturing using creative chat modem
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
hugeblank committed Aug 8, 2022
1 parent 090b5cd commit cf8f994
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.13.3
fabric_version=0.48.0+1.18.2

# Mod Properties
mod_version = 0.3.1
mod_version = 0.3.3
maven_group = dev.hugeblank
archives_base_name = allium_peripherals

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/hugeblank/mixin/ChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ protected void onChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci, Strin
if (!player.getEntityWorld().isClient) {
Allium.debug( "Catchers: " + IChatCatcher.CATCHERS);
for (ChatModemState modem : IChatCatcher.CATCHERS) {
if (player.getUuid().equals(modem.getBound().uuid()) || modem.creative) {
if (modem.creative || modem.isBound() && player.getUuid().equals(modem.getBound().uuid())) {
boolean c = modem.handleChatEvents(packet.getChatMessage(), player);
if (c) cancel = true;
Allium.debug("World: " + (player.getEntityWorld().isClient() ? "client" : "server") + ", cancelled: " + (cancel ? "yes" : "no"));
} else if (!modem.isBound()) { // This should never happen.
Allium.debug("Modem " + modem + " is registered as a handler, but has no bound player");
}
}
if (cancel) ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.text.LiteralText;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Set;

Expand Down Expand Up @@ -42,7 +43,8 @@ private void setOpen( boolean state) {
public synchronized void setBound(PlayerInfo info) {
this.playerInfo = info;
}
public PlayerInfo getBound() {

public @Nullable PlayerInfo getBound() {
return playerInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import org.jetbrains.annotations.NotNull;
import org.squiddev.cobalt.Constants;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.UUID;

public abstract class ChatPeripheral implements IDynamicPeripheral {

Expand Down Expand Up @@ -53,7 +51,7 @@ public void setPlayer(PlayerEntity player) {
}
}

public PlayerInfo getBoundPlayer() {
public @Nullable PlayerInfo getBoundPlayer() {
return modem.getBound();
}

Expand Down Expand Up @@ -109,6 +107,7 @@ public MethodResult callMethod(@Nonnull IComputerAccess computer, @Nonnull ILuaC
case 4:
//getBoundPlayer
PlayerInfo info = getBoundPlayer();
if (info == null) return MethodResult.of();
return MethodResult.of(info.playerName(), info.uuid().toString());
default:
return MethodResult.of();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"id": "allium",
"id": "allium_peripherals",
"version": "${version}",

"name": "Allium Peripherals",
Expand Down

0 comments on commit cf8f994

Please sign in to comment.