Skip to content

Commit

Permalink
fix logging crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyfts authored and Dream-Master committed Dec 23, 2023
1 parent 1d450ad commit b17787e
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
Expand Down Expand Up @@ -285,6 +286,11 @@ private static String getPos(int x, int y, int z) {
return String.format("[%d, %d, %d]", x, y, z);
}

private static String getHeldItemName(EntityPlayer player) {
ItemStack stack = player.getHeldItem();
return stack == null ? "Empty Hand" : stack.getDisplayName();
}

@SubscribeEvent
public void onBlockBreakLog(BlockEvent.BreakEvent event) {
EntityPlayer player = event.getPlayer();
Expand Down Expand Up @@ -330,7 +336,7 @@ public void onRightClickItemLog(PlayerInteractEvent event) {
String.format(
"%s clicked %s in air at %s in %s",
playerMP.getDisplayName(),
playerMP.getHeldItem().getDisplayName(),
getHeldItemName(playerMP),
getPos(event.x, event.y, event.z),
getDim(playerMP)));
}
Expand All @@ -349,7 +355,7 @@ public void onEntityAttackedLog(AttackEntityEvent event) {
"%s attacked %s with %s at %s in %s",
playerMP.getDisplayName(),
targetPlayer.getDisplayName(),
playerMP.getHeldItem().getDisplayName(),
getHeldItemName(playerMP),
getPos((int) playerMP.posX, (int) playerMP.posY, (int) playerMP.posZ),
getDim(playerMP)));
}
Expand All @@ -360,7 +366,7 @@ public void onEntityAttackedLog(AttackEntityEvent event) {
"%s attacked %s with %s at %s in %s",
playerMP.getDisplayName(),
targetCreature.getCommandSenderName(),
playerMP.getHeldItem().getDisplayName(),
getHeldItemName(playerMP),
getPos((int) playerMP.posX, (int) playerMP.posY, (int) playerMP.posZ),
getDim(playerMP)));
}
Expand Down

0 comments on commit b17787e

Please # to comment.