Fixes related to OwnerLedger and GameProfile

Change the name of method getOwnerName to getOwnerProfile and improved
robustness for when owner (GameProfile) is missing. Fixes #66
This commit is contained in:
SandGrainOne committed 2014-08-03 20:32:56 +02:00
1 parent 420c5497e9
commit 1ec85b4e79
17 files changed
+67 -45

No files matched your search

@@ -10,6 +10,8 @@ package forestry.apiculture.gadgets;
import java.util.LinkedHashSet;
import java.util.Set;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
@@ -18,11 +20,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.inventory.ISpecialInventory;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
@@ -836,4 +835,10 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IS
public boolean isOwnable() {
return true;
}
/* IHousing */
@Override
public GameProfile getOwnerName() {
return this.getOwnerProfile();
}
}
@@ -7,6 +7,8 @@
******************************************************************************/
package forestry.apiculture.gadgets;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
@@ -14,7 +16,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
@@ -435,4 +436,10 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
public boolean onEggLaid(IBee queen) {
return false;
}
/* IHousing */
@Override
public GameProfile getOwnerName() {
return this.getOwnerProfile();
}
}
@@ -12,6 +12,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -19,12 +21,9 @@ import net.minecraft.network.Packet;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.arboriculture.IAlleleFruit;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ILeafTickHandler;
@@ -422,4 +421,9 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
return !isDestroyed() && caterpillar == null;
}
/* IHousing */
@Override
public GameProfile getOwnerName() {
return this.getOwnerProfile();
}
}
@@ -57,7 +57,7 @@ public class TileSapling extends TileTreeContainer {
WorldGenerator generator = this.getTree().getTreeGenerator(worldObj, xCoord, yCoord, zCoord, bonemealed);
if (generator.generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord)) {
PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwnerName()).registerBirth(getTree());
PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwnerProfile()).registerBirth(getTree());
return 2;
}
@@ -138,7 +138,7 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
}
@Override
public GameProfile getOwnerName() {
public GameProfile getOwnerProfile() {
return owner;
}
@@ -58,7 +58,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
if (!(tile instanceof TileSapling))
return Utils.getForestryPlayerProfile();
return ((TileSapling) tile).getOwnerName();
return ((TileSapling) tile).getOwnerProfile();
}
public abstract void preGenerate();
@@ -24,18 +24,16 @@ import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.IFluidHandler;
import forestry.core.interfaces.IOwnable;
import forestry.core.items.ItemNBTTile;
import forestry.core.proxy.Proxies;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StringUtil;
public class BlockBase extends BlockForestry {
@@ -176,10 +174,18 @@ public class BlockBase extends BlockForestry {
if (!Proxies.common.isSimulating(world))
return true;
if (tile.allowsInteraction(player))
if (tile.allowsInteraction(player)) {
tile.openGui(player, tile);
else
player.addChatMessage(new ChatComponentTranslation("\u00A7c%s %s", new ChatComponentText(tile.getOwnerName().getName()), new ChatComponentTranslation("chat.accesslocked")));
}
else {
String ownerName = StringUtil.localize("gui.derelict");
if (tile.getOwnerProfile() != null)
ownerName = tile.getOwnerProfile().getName();
player.addChatMessage(new ChatComponentTranslation("\u00A7c%s %s", new ChatComponentText(ownerName), new ChatComponentTranslation("chat.accesslocked")));
}
return true;
}
@@ -14,9 +14,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
import forestry.api.core.ITileStructure;
import forestry.core.proxy.Proxies;
import forestry.core.utils.StringUtil;
public abstract class BlockStructure extends BlockForestry {
@@ -68,10 +68,17 @@ public abstract class BlockStructure extends BlockForestry {
if (!((ITileStructure) tile).isIntegratedIntoStructure())
return false;
if (tile.allowsInteraction(player))
if (tile.allowsInteraction(player)) {
tile.openGui(player);
else
player.addChatMessage(new ChatComponentTranslation("\u00A7c%s %s", new ChatComponentText(tile.getOwnerName().getName()), new ChatComponentTranslation("chat.accesslocked")));
}
else {
String ownerName = StringUtil.localize("gui.derelict");
if (tile.getOwnerProfile() != null)
ownerName = tile.getOwnerProfile().getName();
player.addChatMessage(new ChatComponentTranslation("\u00A7c%s %s", new ChatComponentText(ownerName), new ChatComponentTranslation("chat.accesslocked")));
}
return true;
}
@@ -256,7 +256,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
}
@Override
public GameProfile getOwnerName() {
public GameProfile getOwnerProfile() {
return owner;
}
@@ -275,14 +275,14 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
@Override
public boolean isOwner(EntityPlayer player) {
if (owner != null)
return owner.equals(player.getGameProfile().getId());
return owner.getId().compareTo(player.getPersistentID()) == 0;
else
return false;
}
@Override
public boolean switchAccessRule(EntityPlayer player) {
if (owner != null && !owner.equals(player.getGameProfile()))
if (!isOwner(player))
return false;
if (access.ordinal() < EnumAccess.values().length - 1)
@@ -349,11 +349,6 @@ public class TileMachine extends TileForestry implements ISpecialInventory, ICli
return 0;
}
// @Override
// public boolean canAccess(String username) {
// return isOwned() && getOwnerName().equals(username);
// }
@Override
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
if (getAccess() == EnumAccess.PRIVATE)
@@ -11,7 +11,6 @@ import java.util.Locale;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import forestry.core.interfaces.IOwnable;
import forestry.core.network.PacketCoordinates;
import forestry.core.network.PacketIds;
@@ -71,11 +70,12 @@ public class OwnerLedger extends Ledger {
manager.minecraft.fontRenderer.drawStringWithShadow(StringUtil.localize("gui.owner"), x + 22, y + 8, manager.gui.fontColor.get("ledger.owner.header"));
String owner;
if ((owner = tile.getOwnerName().getName()) == null)
owner = StringUtil.localize("gui.derelict");
manager.minecraft.fontRenderer.drawString(owner, x + 22, y + 20, manager.gui.fontColor.get("ledger.owner.text"));
String ownerName = StringUtil.localize("gui.derelict");
if (tile.getOwnerProfile() != null)
ownerName = tile.getOwnerProfile().getName();
manager.minecraft.fontRenderer.drawString(ownerName, x + 22, y + 20, manager.gui.fontColor.get("ledger.owner.text"));
if (!playerIsOwner)
return;
@@ -90,8 +90,8 @@ public class OwnerLedger extends Ledger {
@Override
public String getTooltip() {
if (tile.getOwnerName() != null)
return StringUtil.localize("gui.owner") + ": " + tile.getOwnerName();
if (tile.getOwnerProfile() != null)
return StringUtil.localize("gui.owner") + ": " + tile.getOwnerProfile().getName();
else
return StringUtil.localize("gui.derelict");
}
@@ -19,7 +19,7 @@ public interface IOwnable {
boolean isOwned();
GameProfile getOwnerName();
GameProfile getOwnerProfile();
void setOwner(EntityPlayer player);
@@ -233,8 +233,6 @@ public class Butterfly extends IndividualLiving implements IButterfly {
if ((chance = mutation.getChance(nursery, allele0, allele1, genome0, genome1)) > 0)
if (world.rand.nextFloat()*100 < chance) {
//IApiaristTracker breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(world, housing.getOwnerName());
//breedingTracker.registerMutation(mutation);
return PluginLepidopterology.butterflyInterface.templateAsChromosomes(mutation.getTemplate());
}
}
@@ -55,7 +55,7 @@ public class POBox extends WorldSavedData implements IInventory {
letters.writeToNBT(nbttagcompound);
}
public GameProfile getOwnerName() {
public GameProfile getOwnerProfile() {
return this.owner;
}
@@ -100,10 +100,10 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
if (!Proxies.common.isSimulating(worldObj))
return new InventoryAdapter(POBox.SLOT_SIZE, "Letters");
if (getOwnerName() == null)
if (getOwnerProfile() == null)
return new InventoryAdapter(POBox.SLOT_SIZE, "Letters");
return PostRegistry.getOrCreatePOBox(worldObj, getOwnerName());
return PostRegistry.getOrCreatePOBox(worldObj, getOwnerProfile());
}
private IPostalState tryDispatchLetter(ItemStack letterstack, boolean dispatchLetter) {
@@ -171,7 +171,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
}
this.moniker = moniker;
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerName(), this.moniker);
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), this.moniker);
setErrorState(EnumErrorCode.OK);
sendNetworkUpdate();
} else
@@ -188,7 +188,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
if (this.moniker == null)
return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV");
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerName(), this.moniker);
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), this.moniker);
}
/* ISPECIALINVENTORY */
@@ -54,7 +54,7 @@ public class ContainerMailbox extends ContainerForestry {
ItemStack stack = super.slotClick(slotIndex, button, par3, player);
if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null)
PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), mailbox.getOwnerName(), mailinventory.getPOBoxInfo());
PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), mailbox.getOwnerProfile(), mailinventory.getPOBoxInfo());
return stack;
}