mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 20:12:19 +00:00
Fix #1325 Null Pointer Exception from broken mailbox
This commit is contained in:
1 parent
c0a22f4a28
commit
e9809238de
15 files changed
+51
-43
No files matched your search
@@ -17,9 +17,5 @@ public interface IMailAddress extends INbtWritable {
|
||||
|
||||
boolean isValid();
|
||||
|
||||
boolean isPlayer();
|
||||
|
||||
boolean isTrader();
|
||||
|
||||
GameProfile getPlayerProfile();
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -18,9 +19,10 @@ public interface IPostRegistry {
|
||||
IPostOffice getPostOffice(World world);
|
||||
|
||||
/* MAIL ADDRESSES */
|
||||
IMailAddress getMailAddress(GameProfile gameProfile);
|
||||
|
||||
IMailAddress getMailAddress(String traderName);
|
||||
@Nonnull
|
||||
IMailAddress getMailAddress(@Nonnull GameProfile gameProfile);
|
||||
|
||||
IMailAddress getMailAddress(@Nonnull String traderName);
|
||||
|
||||
/* LETTERS */
|
||||
boolean isLetter(ItemStack itemstack);
|
||||
|
||||
@@ -130,7 +130,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(@Nullable GameProfile owner) {
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -100,7 +101,7 @@ public final class AccessHandler implements IAccessHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(GameProfile owner) {
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
for (IAccessOwnerListener listener : accessOwnerListeners) {
|
||||
listener.onOwnerSet(owner);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -90,7 +91,7 @@ public class FakeAccessHandler implements IAccessHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(GameProfile owner) {
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.access;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -17,10 +20,11 @@ import com.mojang.authlib.GameProfile;
|
||||
public interface IOwnable {
|
||||
|
||||
boolean isOwned();
|
||||
|
||||
|
||||
@Nullable
|
||||
GameProfile getOwner();
|
||||
|
||||
void setOwner(GameProfile owner);
|
||||
|
||||
void setOwner(@Nonnull GameProfile owner);
|
||||
|
||||
boolean isOwner(EntityPlayer player);
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(GameProfile owner) {
|
||||
public void setOwner(@Nonnull GameProfile owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,20 +90,10 @@ public class MailAddress implements INbtWritable, IMailAddress {
|
||||
public boolean isValid() {
|
||||
return gameProfile.getName() != null && !PlayerUtil.isSameGameProfile(gameProfile, invalidGameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayer() {
|
||||
return type == EnumAddressee.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrader() {
|
||||
return type == EnumAddressee.TRADER;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameProfile getPlayerProfile() {
|
||||
if (!this.isPlayer()) {
|
||||
if (this.type != EnumAddressee.PLAYER) {
|
||||
return null;
|
||||
}
|
||||
return gameProfile;
|
||||
@@ -127,7 +117,7 @@ public class MailAddress implements INbtWritable, IMailAddress {
|
||||
@Override
|
||||
public String toString() {
|
||||
String name = getName().toLowerCase(Locale.ENGLISH);
|
||||
if (isPlayer()) {
|
||||
if (getType() == EnumAddressee.PLAYER) {
|
||||
return type + "-" + name + '-' + gameProfile.getId();
|
||||
} else {
|
||||
return type + "-" + name;
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
@@ -33,7 +34,7 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
|
||||
public POBox(IMailAddress address) {
|
||||
super(SAVE_NAME + address);
|
||||
if (!address.isPlayer()) {
|
||||
if (address.getType() != EnumAddressee.PLAYER) {
|
||||
throw new IllegalArgumentException("POBox address must be a player");
|
||||
}
|
||||
this.address = address;
|
||||
@@ -85,7 +86,7 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
continue;
|
||||
}
|
||||
ILetter letter = new Letter(letters.getStackInSlot(i).getTagCompound());
|
||||
if (letter.getSender().isPlayer()) {
|
||||
if (letter.getSender().getType() == EnumAddressee.PLAYER) {
|
||||
playerLetters++;
|
||||
} else {
|
||||
tradeLetters++;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
@@ -47,7 +48,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidPOBox(World world, IMailAddress address) {
|
||||
return address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
return address.getType() == EnumAddressee.PLAYER && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
public static POBox getPOBox(World world, IMailAddress address) {
|
||||
@@ -88,7 +89,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidTradeAddress(World world, IMailAddress address) {
|
||||
return address != null && address.isTrader() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
return address != null && address.getType() == EnumAddressee.TRADER && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,13 +174,14 @@ public class PostRegistry implements IPostRegistry {
|
||||
return office;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IMailAddress getMailAddress(GameProfile gameProfile) {
|
||||
public IMailAddress getMailAddress(@Nonnull GameProfile gameProfile) {
|
||||
return new MailAddress(gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(String traderName) {
|
||||
public IMailAddress getMailAddress(@Nonnull String traderName) {
|
||||
return new MailAddress(traderName);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.world.WorldSavedData;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumPostage;
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.ILetter;
|
||||
@@ -64,7 +65,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
public TradeStation(GameProfile owner, IMailAddress address) {
|
||||
super(SAVE_NAME + address);
|
||||
if (!address.isTrader()) {
|
||||
if (address.getType() != EnumAddressee.TRADER) {
|
||||
throw new IllegalArgumentException("TradeStation address must be a trader");
|
||||
}
|
||||
this.owner = owner;
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumTradeStationState;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.ITradeStationInfo;
|
||||
@@ -26,7 +27,7 @@ public class TradeStationInfo implements ITradeStationInfo {
|
||||
private final EnumTradeStationState state;
|
||||
|
||||
public TradeStationInfo(IMailAddress address, GameProfile owner, ItemStack tradegood, ItemStack[] required, EnumTradeStationState state) {
|
||||
if (!address.isTrader()) {
|
||||
if (address.getType() != EnumAddressee.TRADER) {
|
||||
throw new IllegalArgumentException("TradeStation address must be a trader");
|
||||
}
|
||||
this.address = address;
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -126,7 +126,7 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
getLetter().setRecipient(recipient);
|
||||
|
||||
// Update the trading info
|
||||
if (recipient == null || recipient.isTrader()) {
|
||||
if (recipient == null || recipient.getType() == EnumAddressee.TRADER) {
|
||||
updateTradeInfo(player.worldObj, recipient);
|
||||
}
|
||||
|
||||
@@ -134,12 +134,13 @@ public class ContainerLetter extends ContainerItemInventory<ItemInventoryLetter>
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfoResponse(type, tradeInfo, recipient), player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IMailAddress getRecipient(MinecraftServer minecraftServer, String recipientName, EnumAddressee type) {
|
||||
switch (type) {
|
||||
case PLAYER: {
|
||||
GameProfile gameProfile = minecraftServer.getPlayerProfileCache().getGameProfileForUsername(recipientName);
|
||||
if (gameProfile == null) {
|
||||
gameProfile = new GameProfile(new UUID(0, 0), recipientName);
|
||||
return null;
|
||||
}
|
||||
return PostManager.postRegistry.getMailAddress(gameProfile);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -63,13 +65,16 @@ public class TileMailbox extends TileBase implements IMailContainer {
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
if (!isLinked) {
|
||||
getOrCreateMailInventory(worldObj, getAccessHandler().getOwner());
|
||||
GameProfile owner = getAccessHandler().getOwner();
|
||||
if (owner != null) {
|
||||
getOrCreateMailInventory(worldObj, owner);
|
||||
}
|
||||
isLinked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* MAIL HANDLING */
|
||||
public IInventory getOrCreateMailInventory(World world, GameProfile playerProfile) {
|
||||
public IInventory getOrCreateMailInventory(World world, @Nonnull GameProfile playerProfile) {
|
||||
if (world.isRemote) {
|
||||
return getInternalInventory();
|
||||
}
|
||||
@@ -93,8 +98,11 @@ public class TileMailbox extends TileBase implements IMailContainer {
|
||||
|
||||
@Override
|
||||
public boolean hasMail() {
|
||||
|
||||
IInventory mailInventory = getOrCreateMailInventory(worldObj, getAccessHandler().getOwner());
|
||||
GameProfile owner = getAccessHandler().getOwner();
|
||||
if (owner == null) {
|
||||
return false;
|
||||
}
|
||||
IInventory mailInventory = getOrCreateMailInventory(worldObj, owner);
|
||||
for (int i = 0; i < mailInventory.getSizeInventory(); i++) {
|
||||
if (mailInventory.getStackInSlot(i) != null) {
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user