Fixed server crash when a player joins

This commit is contained in:
Sollace 2019-01-31 17:21:14 +02:00
parent fd3edb01c4
commit 38ec547662
9 changed files with 35 additions and 26 deletions

View file

@ -6,7 +6,6 @@ import java.util.Map;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.minelittlepony.pony.data.PonyRace; import com.minelittlepony.pony.data.PonyRace;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -59,18 +58,13 @@ public enum Race {
return canFly() && this != CHANGELING; return canFly() && this != CHANGELING;
} }
public String getDisplayString() { public String getTranslationKey() {
return I18n.format(getTranslationString());
}
public String getTranslationString() {
return String.format("unicopia.race.%s", name().toLowerCase()); return String.format("unicopia.race.%s", name().toLowerCase());
} }
public boolean isSameAs(String s) { public boolean isSameAs(String s) {
return name().equalsIgnoreCase(s) return name().equalsIgnoreCase(s)
|| getTranslationString().equalsIgnoreCase(s) || getTranslationKey().equalsIgnoreCase(s);
|| getDisplayString().equalsIgnoreCase(s);
} }
public static Race fromName(String s, Race def) { public static Race fromName(String s, Race def) {

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.forgebullshit.FUF; import com.minelittlepony.unicopia.forgebullshit.FUF;
@ -43,6 +45,12 @@ public class UClient {
return null; return null;
} }
@FUF(reason = "Forced client Separation")
@Nullable
public EntityPlayer getPlayerByUUID(UUID playerId) {
return null;
}
@FUF(reason = "Forced client Separation") @FUF(reason = "Forced client Separation")
public boolean isClientPlayer(@Nullable EntityPlayer player) { public boolean isClientPlayer(@Nullable EntityPlayer player) {
return false; return false;

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.jumpingcastle.api.Target; import com.minelittlepony.jumpingcastle.api.Target;
@ -69,11 +71,24 @@ public class UnicopiaClient extends UClient {
} }
} }
@Override
@Nullable @Nullable
public EntityPlayer getPlayer() { public EntityPlayer getPlayer() {
return Minecraft.getMinecraft().player; return Minecraft.getMinecraft().player;
} }
@Override
@Nullable
public EntityPlayer getPlayerByUUID(UUID playerId) {
Minecraft mc = Minecraft.getMinecraft();
if (mc.player.getUniqueID().equals(playerId)) {
return mc.player;
}
return mc.world.getPlayerEntityByUUID(playerId);
}
@Override @Override
public boolean isClientPlayer(@Nullable EntityPlayer player) { public boolean isClientPlayer(@Nullable EntityPlayer player) {
if (getPlayer() == player) { if (getPlayer() == player) {

View file

@ -91,7 +91,7 @@ class CommandSpecies extends CommandBase {
String name = "commands.race.tell."; String name = "commands.race.tell.";
name += player == sender ? "self" : "other"; name += player == sender ? "self" : "other";
ITextComponent race = new TextComponentTranslation(spec.getTranslationString()); ITextComponent race = new TextComponentTranslation(spec.getTranslationKey());
ITextComponent message = new TextComponentTranslation(name); ITextComponent message = new TextComponentTranslation(name);
race.getStyle().setColor(TextFormatting.GOLD); race.getStyle().setColor(TextFormatting.GOLD);

View file

@ -4,6 +4,8 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.init.MobEffects; import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public enum Toxicity { public enum Toxicity {
SAFE(0, 0), SAFE(0, 0),
@ -46,6 +48,7 @@ public enum Toxicity {
return String.format("toxicity.%s.name", name().toLowerCase()); return String.format("toxicity.%s.name", name().toLowerCase());
} }
@SideOnly(Side.CLIENT)
public String getTooltip() { public String getTooltip() {
TextFormatting color = toxicWhenCooked() ? TextFormatting.RED : toxicWhenRaw() ? TextFormatting.DARK_PURPLE : TextFormatting.GRAY; TextFormatting color = toxicWhenCooked() ? TextFormatting.RED : toxicWhenRaw() ? TextFormatting.DARK_PURPLE : TextFormatting.GRAY;

View file

@ -12,6 +12,7 @@ import com.minelittlepony.jumpingcastle.api.IChannel;
import com.minelittlepony.jumpingcastle.api.IMessage; import com.minelittlepony.jumpingcastle.api.IMessage;
import com.minelittlepony.jumpingcastle.api.IMessageHandler; import com.minelittlepony.jumpingcastle.api.IMessageHandler;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.player.PlayerSpeciesList;
@ -53,7 +54,7 @@ public class MsgPlayerCapabilities implements IMessage, IMessageHandler<MsgPlaye
@Override @Override
public void onPayload(MsgPlayerCapabilities message, IChannel channel) { public void onPayload(MsgPlayerCapabilities message, IChannel channel) {
EntityPlayer self = IPlayer.getPlayerFromClient(senderId); EntityPlayer self = UClient.instance().getPlayerByUUID(senderId);
if (self == null) { if (self == null) {
Unicopia.log.warn("[Unicopia] [CLIENT] [MsgPlayerCapabilities] Player with id %s was not found!\n", senderId.toString()); Unicopia.log.warn("[Unicopia] [CLIENT] [MsgPlayerCapabilities] Player with id %s was not found!\n", senderId.toString());

View file

@ -8,7 +8,6 @@ import com.minelittlepony.unicopia.enchanting.IPageOwner;
import com.minelittlepony.unicopia.network.ITransmittable; import com.minelittlepony.unicopia.network.ITransmittable;
import com.minelittlepony.unicopia.spell.ICaster; import com.minelittlepony.unicopia.spell.ICaster;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
@ -62,14 +61,4 @@ public interface IPlayer extends ICaster<EntityPlayer>, IRaceContainer<EntityPla
return null; return null;
} }
static EntityPlayer getPlayerFromClient(UUID playerId) {
Minecraft mc = Minecraft.getMinecraft();
if (mc.player.getUniqueID().equals(playerId)) {
return mc.player;
}
return mc.world.getPlayerEntityByUUID(playerId);
}
} }

View file

@ -38,7 +38,9 @@ class PlayerAttributes {
loadStrength += InventoryOfHolding.decodeStackWeight(item); loadStrength += InventoryOfHolding.decodeStackWeight(item);
} }
entity.capabilities.setPlayerWalkSpeed(0.1F - (float)(loadStrength / 100000)); if (entity.world.isRemote) {
entity.capabilities.setPlayerWalkSpeed(0.1F - (float)(loadStrength / 100000));
}
applyAttribute(entity, SharedMonsterAttributes.ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth()); applyAttribute(entity, SharedMonsterAttributes.ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());
applyAttribute(entity, SharedMonsterAttributes.KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth()); applyAttribute(entity, SharedMonsterAttributes.KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth());

View file

@ -127,8 +127,6 @@ class PlayerCapabilities implements IPlayer {
@Override @Override
public void sendCapabilities(boolean full) { public void sendCapabilities(boolean full) {
if (!getOwner().getEntityWorld().isRemote) { if (!getOwner().getEntityWorld().isRemote) {
System.out.println("[SERVER] Sending player capabilities.");
if (full) { if (full) {
Unicopia.channel.broadcast(new MsgPlayerCapabilities(this)); Unicopia.channel.broadcast(new MsgPlayerCapabilities(this));
} else { } else {
@ -211,12 +209,11 @@ class PlayerCapabilities implements IPlayer {
} }
} }
@Override @Override
public boolean stepOnCloud() { public boolean stepOnCloud() {
EntityPlayer player = getOwner(); EntityPlayer player = getOwner();
if ((player.fallDistance > 1) || player.distanceWalkedOnStepModified > nextStepDistance) { if (player.fallDistance > 1 || player.distanceWalkedOnStepModified > nextStepDistance) {
nextStepDistance = player.distanceWalkedOnStepModified + 2; nextStepDistance = player.distanceWalkedOnStepModified + 2;
player.fallDistance = 0; player.fallDistance = 0;