Docs for NetworkHelper

This commit is contained in:
Nick 2015-12-01 21:55:56 -08:00
parent 02956798f0
commit b97f7d81c4
2 changed files with 42 additions and 4 deletions

View file

@ -17,6 +17,14 @@ public class NetworkHelper {
// Get
/**
* Gets the SoulNetwork for the player.
*
* @param ownerName - The name of the SoulNetwork owner
* @param world - The world
*
* @return - The SoulNetwork for the given name.
*/
public static SoulNetwork getSoulNetwork(String ownerName, World world) {
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, ownerName);
@ -28,6 +36,13 @@ public class NetworkHelper {
return network;
}
/**
* Gets the current orb tier of the SoulNetwork.
*
* @param soulNetwork - SoulNetwork to get the tier of.
*
* @return - The Orb tier of the given SoulNetwork
*/
public static int getCurrentMaxOrb(SoulNetwork soulNetwork) {
return soulNetwork.getOrbTier();
}
@ -35,8 +50,13 @@ public class NetworkHelper {
// Syphon
/**
* Syphons from the player and damages them if there was not enough stored LP.
*
* Handles null-checking the player for you.
*
* @param soulNetwork - SoulNetwork to syphon from
* @param toSyphon - Amount of LP to syphon
*
* @return - Whether the action should be performed.
*/
public static boolean syphonAndDamage(SoulNetwork soulNetwork, int toSyphon) {
@ -48,21 +68,39 @@ public class NetworkHelper {
return soulNetwork.syphonAndDamage(toSyphon);
}
public static boolean syphonFromContainer(ItemStack stack, SoulNetwork soulNetwork, int toSyphon) {
/**
* Syphons a player from within a container.
*
* @param stack - ItemStack in the Container.
* @param world - The world the Container is in
* @param toSyphon - Amount of LP to syphon
*
* @return - If the syphon was successful.
*/
public static boolean syphonFromContainer(ItemStack stack, World world, int toSyphon) {
stack = NBTHelper.checkNBT(stack);
String ownerName = stack.getTagCompound().getString(Constants.NBT.OWNER_NAME);
if (Strings.isNullOrEmpty(ownerName))
return false;
SoulNetwork network = getSoulNetwork(ownerName, world);
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, toSyphon);
return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && soulNetwork.syphon(event.syphon) >= toSyphon;
return !(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) && network.syphon(event.syphon) >= toSyphon;
}
// Set
public static void setMaxOrbToMax(SoulNetwork soulNetwork, int maxOrb) {
/**
* Sets the orb tier of the SoulNetwork to the given orb. Will not set
* if the given tier is lower than the current tier.
*
* @param soulNetwork - SoulNetwork to set the orb tier of
* @param maxOrb - Tier of orb to set to
*/
public static void setMaxOrb(SoulNetwork soulNetwork, int maxOrb) {
soulNetwork.setOrbTier(Math.max(maxOrb, soulNetwork.getOrbTier()));
soulNetwork.markDirty();
}

View file

@ -62,7 +62,7 @@ public class ItemBloodOrb extends ItemBindable implements IBloodOrb, IBindable {
return stack;
if (stack.getTagCompound().getString(Constants.NBT.OWNER_NAME).equals(PlayerHelper.getUsernameFromPlayer(player)))
NetworkHelper.setMaxOrbToMax(NetworkHelper.getSoulNetwork(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME), world), getOrbLevel(stack.getItemDamage()));
NetworkHelper.setMaxOrb(NetworkHelper.getSoulNetwork(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME), world), getOrbLevel(stack.getItemDamage()));
NetworkHelper.getSoulNetwork(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME), world).addLifeEssence(200, getMaxEssence(stack.getItemDamage()));
hurtPlayer(player, 200);