prevent possible NPEs when logging but it doesn't work

this is supposed to prevent an NPE when sending a chat message and mc.player is null. still working on it but it doesn't leave any harm to let someone else give it a shot
This commit is contained in:
Bella 2019-12-03 21:51:29 -05:00
parent 69d7047837
commit 16ac69f086
1 changed files with 18 additions and 1 deletions

View File

@ -5,12 +5,15 @@ import me.zeroeightsix.kami.command.syntax.SyntaxChunk;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.util.Wrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentBase;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.minecraft.launchwrapper.LogWrapper.log;
public abstract class Command {
protected String label;
@ -45,7 +48,21 @@ public abstract class Command {
}
public static void sendRawChatMessage(String message){
Wrapper.getPlayer().sendMessage(new ChatMessage(message));
if (isSendable()) {
Wrapper.getPlayer().sendMessage(new ChatMessage(message));
}
else {
log.info("KAMI Blue: Avoided NPE by logging to file instead of chat\n" + message);
}
}
public static boolean isSendable(){
if (Minecraft.getMinecraft().player == null) {
return false;
}
else {
return true;
}
}
protected void setDescription(String description) {