forked from RepoMirrors/kami-blue
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:
parent
69d7047837
commit
16ac69f086
|
@ -5,12 +5,15 @@ import me.zeroeightsix.kami.command.syntax.SyntaxChunk;
|
||||||
import me.zeroeightsix.kami.setting.Setting;
|
import me.zeroeightsix.kami.setting.Setting;
|
||||||
import me.zeroeightsix.kami.setting.Settings;
|
import me.zeroeightsix.kami.setting.Settings;
|
||||||
import me.zeroeightsix.kami.util.Wrapper;
|
import me.zeroeightsix.kami.util.Wrapper;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentBase;
|
import net.minecraft.util.text.TextComponentBase;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static net.minecraft.launchwrapper.LogWrapper.log;
|
||||||
|
|
||||||
public abstract class Command {
|
public abstract class Command {
|
||||||
|
|
||||||
protected String label;
|
protected String label;
|
||||||
|
@ -45,7 +48,21 @@ public abstract class Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendRawChatMessage(String message){
|
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) {
|
protected void setDescription(String description) {
|
||||||
|
|
Loading…
Reference in New Issue