Skip to content

Commit

Permalink
Guard against null players, see #224
Browse files Browse the repository at this point in the history
Cleanup some code to fix warnings
Don't query mojang session server for every sync shell to fill session properties
  • Loading branch information
ichttt committed May 27, 2019
1 parent 69d8e21 commit 7419e7e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Function;
import mcjty.theoneprobe.api.*;
import mcjty.theoneprobe.apiimpl.styles.ProgressStyle;
import me.ichun.mods.sync.common.Sync;
import me.ichun.mods.sync.common.tileentity.TileEntityShellConstructor;
import me.ichun.mods.sync.common.tileentity.TileEntityShellStorage;
Expand All @@ -17,7 +16,6 @@
import java.text.DecimalFormat;

public class HUDHandlerTheOneProbe implements Function<ITheOneProbe, Void>, IProbeInfoProvider {
private static final ProgressStyle STYLE_BUILD_PROGRESS = new ProgressStyle().showText(true).prefix(I18n.translateToLocal("sync.waila.progress") + ": ").suffix("%");
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("##.##");

@Nullable
Expand Down Expand Up @@ -46,7 +44,7 @@ public void addProbeInfo(ProbeMode probeMode, IProbeInfo info, EntityPlayer enti
info.text(I18n.translateToLocal("sync.waila.owner") + ": " + (te.getPlayerName().equals("") ? "None" : te.getPlayerName()));
float progress = te.getBuildProgress() / Sync.config.shellConstructionPowerRequirement;
if (progress < 1 || probeMode == ProbeMode.EXTENDED || probeMode == ProbeMode.DEBUG)
info.progress((int) Math.ceil(progress * 100), 100, STYLE_BUILD_PROGRESS);
info.progress((int) Math.ceil(progress * 100), 100, info.defaultProgressStyle().showText(true).prefix(I18n.translateToLocal("sync.waila.progress") + ": ").suffix("%"));
}
else if (tileEntity instanceof TileEntityShellStorage) {
TileEntityShellStorage te = (TileEntityShellStorage) tileEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<String> getWailaBody(@Nonnull ItemStack itemStack, List<String> curr
if (accessor.getTileEntity() instanceof TileEntityShellConstructor) {
TileEntityShellConstructor tileEntityShellConstructor = (TileEntityShellConstructor) accessor.getTileEntity();
if (config.getConfig("sync.showowner")) currenttip.add(I18n.translateToLocal("sync.waila.owner") + ": " + (tileEntityShellConstructor.getPlayerName().equals("") ? "None" : tileEntityShellConstructor.getPlayerName()));
if (config.getConfig("sync.showprogress")) currenttip.add(I18n.translateToLocal("sync.waila.progress") + ": " + String.valueOf((int) Math.ceil(tileEntityShellConstructor.getBuildProgress() / Sync.config.shellConstructionPowerRequirement * 100)) + "%");
if (config.getConfig("sync.showprogress")) currenttip.add(I18n.translateToLocal("sync.waila.progress") + ": " + (int) Math.ceil(tileEntityShellConstructor.getBuildProgress() / Sync.config.shellConstructionPowerRequirement * 100) + "%");
}
else if (accessor.getTileEntity() instanceof TileEntityShellStorage) {
TileEntityShellStorage tileEntityShellStorage = (TileEntityShellStorage) accessor.getTileEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void worldTick(TickEvent.ClientTickEvent event)
lockedStorage = null;
}

if(!mc.isGamePaused())
if(!mc.isGamePaused() && mc.player != null)
{
for(ShellState state : shells)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public static void get(String playerName, UUID playerUUID, Consumer<ResourceLoca
}
}
if (playerUUID == null) return; //Not much we can do here :(
GameProfile profile = EntityHelper.getGameProfile(playerUUID, playerName);
synchronized (callbackMap) {
Set<Consumer<ResourceLocation>> consumers = callbackMap.getIfPresent(playerName);
if (consumers == null) {
//Make one call per user - again rate limit protection
GameProfile profile = EntityHelper.getGameProfile(playerUUID, playerName); //This also queries auth server for details
Minecraft.getMinecraft().getSkinManager().loadProfileTextures(profile, (type, location, profileTexture) -> {
if (type == MinecraftProfileTexture.Type.SKIN) {
synchronized (callbackMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void doRender(EntityShellDestruction sd, double d, double d1, double d2,
try
{
ThreadDownloadImageData imgDat = (ThreadDownloadImageData)obj;
BufferedImage img = ObfuscationReflectionHelper.getPrivateValue(ThreadDownloadImageData.class, imgDat, "field_110560_d", "bufferedImage");
BufferedImage img = ObfuscationReflectionHelper.getPrivateValue(ThreadDownloadImageData.class, imgDat, "field_110560_d");
if(img != null)
{
int[] imgId = new int[4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void neighborChanged(IBlockState state, World world, BlockPos pos, Block
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof TileEntityDualVertical) {
TileEntityDualVertical dualVertical = (TileEntityDualVertical) tileEntity;
if (!dualVertical.top && !world.getBlockState(pos.add(0, -1, 0)).getBlock().isOpaqueCube(world.getBlockState(pos.add(0, -1, 0)))) {
if (!dualVertical.top && !world.getBlockState(pos.add(0, -1, 0)).isOpaqueCube()) {
world.setBlockToAir(pos);
}
}
Expand Down Expand Up @@ -517,7 +517,7 @@ public boolean hasComparatorInputOverride(IBlockState state) {
public int getComparatorInputOverride(IBlockState blockState, World world, BlockPos pos) {
if (world.getTileEntity(pos) instanceof TileEntityDualVertical) {
TileEntityDualVertical tileEntityDualVertical = (TileEntityDualVertical) world.getTileEntity(pos);
return (int) Math.floor(tileEntityDualVertical.getBuildProgress() / (Sync.config.shellConstructionPowerRequirement / 15));
return (int) Math.floor(tileEntityDualVertical.getBuildProgress() / (Sync.config.shellConstructionPowerRequirement / 15F));
}
else return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.ichun.mods.sync.common.tileentity.TileEntityDualVertical;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSnow;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -77,7 +78,8 @@ else if (stack.isEmpty())
sc.setup(sc1, false, face);
sc1.setup(sc, true, face);
}
world.playSound(null, new BlockPos(((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F)), block1.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (block1.getSoundType().getVolume() + 1.0F) / 2.0F, block1.getSoundType().getPitch() * 0.8F);
SoundType type = block1.getSoundType(state, world, pos, player);
world.playSound(null, pos, type.getPlaceSound(), SoundCategory.BLOCKS, (type.getVolume() + 1.0F) / 2.0F, type.getPitch() * 0.8F);
stack.shrink(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.ichun.mods.sync.common.tileentity.TileEntityTreadmill;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSnow;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -73,8 +74,9 @@ else if (stack.isEmpty())

sc.setup(sc1, false, face);
sc1.setup(sc, true, face);
}
world.playSound(player, new BlockPos(((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F)), block1.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (block1.getSoundType().getVolume() + 1.0F) / 2.0F, block1.getSoundType().getPitch() * 0.8F);
}
SoundType soundType = block1.getSoundType(state, world, pos, player);
world.playSound(player, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
stack.shrink(1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ else if (this.getClass() == TileEntityShellConstructor.class) {
resyncOrigin.markDirty();
if (getPlayerNBT().hasKey("Inventory")) //try inserting persistent items by merging
{
//noinspection ConstantConditions
mergeStoredInv(dummy.inventory);
}
}
Expand Down Expand Up @@ -614,7 +613,7 @@ public void reset() {
public boolean matchesPlayer(EntityPlayer player) {
UUID playerUUID = player.getUniqueID();
String rightName = player.getName();
if (this.playerUUID != null && !EntityPlayer.getOfflineUUID(this.playerName).equals(playerUUID) && playerUUID.equals(this.playerUUID)) {
if (!EntityPlayer.getOfflineUUID(this.playerName).equals(playerUUID) && playerUUID.equals(this.playerUUID)) {
if (!player.world.isRemote && !rightName.equals(this.playerName)) { //Players can change their name, let's take care of this
String oldPlayerName = this.playerName;
Sync.LOGGER.info("Updating player name for UUID " + playerUUID + ": " + oldPlayerName + " -> " + rightName);
Expand Down Expand Up @@ -662,7 +661,7 @@ public void setPlayerName(EntityPlayer player) {
String playerName = player.getName();
if (!playerName.equals(this.playerName)) {
UUID playerUUID = player.getUniqueID();
setPlayerName(playerName, playerUUID == EntityPlayer.getOfflineUUID(playerName) ? null : playerUUID);
setPlayerName(playerName, playerUUID.equals(EntityPlayer.getOfflineUUID(playerName)) ? null : playerUUID);
}
}

Expand Down

0 comments on commit 7419e7e

Please sign in to comment.