Skip to content

Commit

Permalink
Fix a bunch of places where I don't verify that the player has a corp…
Browse files Browse the repository at this point in the history
…oration where I should
  • Loading branch information
pkmnfrk committed Oct 24, 2018
1 parent 364341d commit 83b7fac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mike_caron.megacorp.api.CorporationManager;
import com.mike_caron.megacorp.api.ICorporation;
import com.mike_caron.megacorp.api.ICorporationManager;
import com.mike_caron.megacorp.api.IReward;
import com.mike_caron.megacorp.api.events.CorporationRewardsChangedEvent;
import com.mike_caron.megacorp.block.TEOwnedContainerBase;
Expand Down Expand Up @@ -142,9 +143,11 @@ protected void onWriteNBT(NBTTagCompound tag)

TileEntityCapitalInvestor te = getTE();

if(te.getOwner() != null)
ICorporationManager manager = CorporationManager.getInstance(te.getWorld());

if(te.getOwner() != null && manager.ownerHasCorporation(te.getOwner()))
{
ICorporation corp = CorporationManager.getInstance(te.getWorld()).getCorporationForOwner(te.getOwner());
ICorporation corp = manager.getCorporationForOwner(te.getOwner());

NBTTagList rewards = new NBTTagList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void detectAndSendChanges()
ICorporationManager manager = CorporationManager.get(te.getWorld());


if(owner != null)
if(owner != null && manager.ownerHasCorporation(owner))
{
ICorporation corp = manager.getCorporationForOwner(owner);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mike_caron.megacorp.block.profit_materializer;

import com.mike_caron.megacorp.api.CorporationManager;
import com.mike_caron.megacorp.api.ICorporationManager;
import com.mike_caron.megacorp.block.TEOwnedContainerBase;
import com.mike_caron.megacorp.util.StringUtil;
import net.minecraft.inventory.IInventory;
Expand Down Expand Up @@ -79,10 +80,11 @@ public void detectAndSendChanges()
}

long pr = 0;
ICorporationManager manager = CorporationManager.getInstance(te.getWorld());

if(owner != null)
if(owner != null && manager.ownerHasCorporation(owner))
{
pr = CorporationManager.getInstance(te.getWorld()).getCorporationForOwner(owner).getAvailableProfit();
pr = manager.getCorporationForOwner(owner).getAvailableProfit();
}

if(profitRemaining != pr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mike_caron.megacorp.block.uplink;

import com.mike_caron.megacorp.MegaCorpMod;
import com.mike_caron.megacorp.api.ICorporationManager;
import com.mike_caron.megacorp.block.OwnedMachineBlockBase;
import com.mike_caron.megacorp.impl.Corporation;
import com.mike_caron.megacorp.impl.CorporationManager;
Expand Down Expand Up @@ -70,8 +71,12 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
ItemStack inHand = playerIn.inventory.getCurrentItem();
if(inHand.getItem() == ModItems.blackCard)
{
Corporation corp = (Corporation)CorporationManager.get(worldIn).getCorporationForOwner(te.getOwner());
corp.addProfit(1000);
ICorporationManager manager = CorporationManager.get(te.getWorld());
if(manager.ownerHasCorporation(te.getOwner()))
{
Corporation corp = (Corporation)manager.getCorporationForOwner(te.getOwner());
corp.addProfit(1000);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void detectAndSendChanges()
changed = true;
}

if(owner != null)
if(owner != null && manager.ownerHasCorporation(owner))
{
ICorporation corp = manager.getCorporationForOwner(owner);
if (!corp.getName().equals(corpName))
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/com/mike_caron/megacorp/command/MegaCorpCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mike_caron.megacorp.command;

import com.mike_caron.megacorp.api.ICorporationManager;
import com.mike_caron.megacorp.impl.CorporationManager;
import com.mike_caron.megacorp.impl.Corporation;
import com.mike_caron.megacorp.impl.QuestManager;
Expand Down Expand Up @@ -131,7 +132,14 @@ private static void setRewardLevel(@Nonnull MinecraftServer server, @Nonnull ICo

UUID id = ((EntityPlayerMP)sender).getUniqueID();

Corporation corp = (Corporation)CorporationManager.get(((EntityPlayerMP) sender).getServerWorld()).getCorporationForOwner(id);
ICorporationManager manager = CorporationManager.get(((EntityPlayerMP) sender).getServerWorld());

Corporation corp = null;

if(manager.ownerHasCorporation(id))
{
corp = (Corporation) manager.getCorporationForOwner(id);
}

if(corp == null)
{
Expand Down Expand Up @@ -168,7 +176,13 @@ private static void clearRewards(@Nonnull MinecraftServer server, @Nonnull IComm
{
UUID id = ((EntityPlayerMP)sender).getUniqueID();

Corporation corp = (Corporation)CorporationManager.get(((EntityPlayerMP) sender).getServerWorld()).getCorporationForOwner(id);
ICorporationManager manager = CorporationManager.get(((EntityPlayerMP) sender).getServerWorld());

Corporation corp = null;
if(manager.ownerHasCorporation(id))
{
corp = (Corporation) manager.getCorporationForOwner(id);
}

if(corp == null)
{
Expand All @@ -186,7 +200,13 @@ private static void removeCorporation(@Nonnull MinecraftServer server, @Nonnull
{
UUID id = ((EntityPlayerMP)sender).getUniqueID();

Corporation corp = (Corporation)CorporationManager.get(((EntityPlayerMP) sender).getServerWorld()).getCorporationForOwner(id);
ICorporationManager manager = CorporationManager.get(((EntityPlayerMP) sender).getServerWorld());

Corporation corp = null;
if(manager.ownerHasCorporation(id))
{
corp = (Corporation) manager.getCorporationForOwner(id);
}

if(corp == null)
{
Expand Down

0 comments on commit 83b7fac

Please sign in to comment.