diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java index 75b85f9ea..45b169b2a 100644 --- a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryModPlugin.java @@ -12,9 +12,9 @@ import org.bukkit.plugin.java.JavaPlugin; import com.github.igotyou.FactoryMod.FactoryObject.FactoryType; import com.github.igotyou.FactoryMod.FactoryObject.SubFactoryType; +import com.github.igotyou.FactoryMod.interfaces.Properties; import com.github.igotyou.FactoryMod.managers.FactoryModManager; import com.github.igotyou.FactoryMod.properties.ProductionProperties; -import com.github.igotyou.interfaces.Properties; public class FactoryModPlugin extends JavaPlugin { @@ -25,6 +25,7 @@ public class FactoryModPlugin extends JavaPlugin public static int AMOUNT_OF_RECIPES_TO_REMOVE; public static int PRODUCTION_MAX_TIERS; public static int PRODUCER_UPDATE_CYCLE; + public static String PRODUCTION_SAVES_FILE; public void onEnable() { diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryObject.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryObject.java index 531d8de84..8256822bb 100644 --- a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryObject.java +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/FactoryObject.java @@ -11,9 +11,9 @@ import org.bukkit.block.Dispenser; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import com.github.igotyou.FactoryMod.interfaces.Properties; import com.github.igotyou.FactoryMod.utility.InteractionResponse; import com.github.igotyou.FactoryMod.utility.InteractionResponse.InteractionResult; -import com.github.igotyou.interfaces.Properties; //original file: /** diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/Factorys/Production.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/Factorys/Production.java index 73038b088..6c514ce12 100644 --- a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/Factorys/Production.java +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/Factorys/Production.java @@ -7,9 +7,9 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import com.github.igotyou.FactoryMod.FactoryObject; +import com.github.igotyou.FactoryMod.interfaces.Factory; import com.github.igotyou.FactoryMod.managers.ProductionManager; import com.github.igotyou.FactoryMod.utility.InteractionResponse; -import com.github.igotyou.interfaces.Factory; public class Production extends FactoryObject implements Factory { @@ -39,21 +39,14 @@ public class Production extends FactoryObject implements Factory // TODO add } - public void destroy(ItemStack item) - { - // TODO Auto-generated method stub - } - public void powerOn() { - // TODO Auto-generated method stub - + active = true; } public void powerOff() { - // TODO Auto-generated method stub - + active = false; } public InteractionResponse togglePower() @@ -62,10 +55,19 @@ public class Production extends FactoryObject implements Factory return null; } - public Location getLocation() + public Location getCenterLocation() { - // TODO Auto-generated method stub - return null; + return factoryLocation; + } + + public Location getInventoryLocation() + { + return factoryInventoryLocation; + } + + public Location getPowerSourceLocation() + { + return factoryPowerSource; } } diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Factory.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Factory.java new file mode 100644 index 000000000..63397a882 --- /dev/null +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Factory.java @@ -0,0 +1,52 @@ +package com.github.igotyou.FactoryMod.interfaces; + +import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; + +import com.github.igotyou.FactoryMod.utility.InteractionResponse; +//original file: +/** + * Machine.java + * Purpose: An interface for machines to implement with basic functionality + * + * @author MrTwiggy + * @version 0.1 1/14/13 + */ +//edited version: +/** +* Factory.java +* Purpose: An interface for machines to implement with basic functionality +* @author igotyou +* +*/ +public interface Factory +{ + /** + * Updates the machine + */ + public void update(); + + /** + * Powers on the machine + */ + public void powerOn(); + + /** + * Powers off the machine + */ + public void powerOff(); + + /** + * Toggles the current power state and returns interaction response + */ + public InteractionResponse togglePower(); + + /** + * Returns the location of the machine + */ + public Location getCenterLocation(); + + public Location getInventoryLocation(); + + public Location getPowerSourceLocation(); +} \ No newline at end of file diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Manager.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Manager.java new file mode 100644 index 000000000..daa9bff42 --- /dev/null +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Manager.java @@ -0,0 +1,74 @@ +package com.github.igotyou.FactoryMod.interfaces; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.Location; + +import com.github.igotyou.FactoryMod.utility.InteractionResponse; + +//original file: +/** +* Manager.java +* Purpose: Interface for Manager objects for basic manager functionality +* +* @author MrTwiggy +* @version 0.1 1/08/13 +*/ +//edited version: +/** +* Manager.java +* Purpose: Interface for Manager objects for basic manager functionality +* @author igotyou +* +*/ + +public interface Manager +{ + +/** +* Saves the machine objects list of this manager to file +*/ + public void save(File file) throws IOException; + +/** +* Loads machine objects list of this manager from file +*/ + public void load(File file) throws IOException; + +/** +* Updates all the machines from this manager's machine object list +*/ + public void updateFactorys(); + +/** +* Attempts to create a new machine for this manager +*/ + public InteractionResponse createFactory(Location factoryLocation, Location inventoryLocation, Location powerLocation); + +/** +* Creates a machine from an existing machine data object +*/ + public InteractionResponse addFactory(Factory factory); + +/** +* Returns the machine (if any exists) at the given location from this manager +*/ + public Factory getFactory(Location factoryLocation); + +/** +* Returns whether a machine exists at the given location +*/ + public boolean factoryExistsAt(Location factoryLocation); + +/** +* Removes the given machine from the object list +*/ + public void removeFactory(Factory factory); + +/** +* Returns the saves file name for this manager +*/ + public String getSavesFileName(); + +} \ No newline at end of file diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Properties.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Properties.java new file mode 100644 index 000000000..d7f53f58e --- /dev/null +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Properties.java @@ -0,0 +1,33 @@ +package com.github.igotyou.FactoryMod.interfaces; + +import java.util.HashMap; + +import org.bukkit.Material; + +//original file: +/** + * Properties.java + * Purpose: Interface for Properties objects for basic properties functionality + * + * @author MrTwiggy + * @version 0.1 1/17/13 + */ +//edited version: +/** +* Properties.java + * Purpose: Interface for Properties objects for basic properties functionality +* @author igotyou +* +*/ +public interface Properties +{ + /** + * Returns the amount of upgrade materials required to reach this tier + */ + public HashMap getBuildAmount(); + + /** + * Returns the material used to upgrade to this tier + */ + public HashMap getBuildMaterial(); +} \ No newline at end of file diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Recipe.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Recipe.java new file mode 100644 index 000000000..2e2f23de1 --- /dev/null +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/interfaces/Recipe.java @@ -0,0 +1,27 @@ +package com.github.igotyou.FactoryMod.interfaces; + +import java.util.HashMap; + +import org.bukkit.Material; + +public interface Recipe +{ + //how many output do we produce at once? + public int getBatchAmount(); + + //the output of this recipe + public Material getOutput(); + + //get the materials needed for one output + public HashMap getInputMaterial(); + + //get the amount of above material nedded + public HashMap getInputAmount(); + + //get the recipes name, example: Iron Pickaxe + public String getRecipeName(); + + //get production time in update cycles + public int getProductionTime(); + +} diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java index daff71086..8bcd709d5 100644 --- a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/managers/ProductionManager.java @@ -16,11 +16,11 @@ import org.bukkit.inventory.Inventory; import com.github.igotyou.FactoryMod.FactoryModPlugin; import com.github.igotyou.FactoryMod.FactoryObject.SubFactoryType; import com.github.igotyou.FactoryMod.Factorys.Production; +import com.github.igotyou.FactoryMod.interfaces.Factory; +import com.github.igotyou.FactoryMod.interfaces.Manager; import com.github.igotyou.FactoryMod.properties.ProductionProperties; import com.github.igotyou.FactoryMod.utility.InteractionResponse; import com.github.igotyou.FactoryMod.utility.InteractionResponse.InteractionResult; -import com.github.igotyou.interfaces.Factory; -import com.github.igotyou.interfaces.Manager; public class ProductionManager implements Manager { @@ -60,7 +60,7 @@ public class ProductionManager implements Manager }, 0L, FactoryModPlugin.PRODUCER_UPDATE_CYCLE); } - public InteractionResponse createFactory(Location factoryLocation, Location inventoryLocation, Location powerLocation) + public InteractionResponse createFactory(Location factoryLocation, Location inventoryLocation, Location powerSourceLocation) { if (!factoryExistsAt(factoryLocation)) { @@ -87,7 +87,7 @@ public class ProductionManager implements Manager } if (hasMaterials == true && subFactoryType != null) { - Production production = new Production(factoryLocation, inventoryLocation, powerLocation,subFactoryType); + Production production = new Production(factoryLocation, inventoryLocation, powerSourceLocation,subFactoryType); if (production.buildMaterialAvailable(properties.get(subFactoryType))) { addFactory(production); @@ -102,32 +102,43 @@ public class ProductionManager implements Manager public InteractionResponse addFactory(Factory factory) { - // TODO Auto-generated method stub - return null; + Production production = (Production) factory; + if (production.getCenterLocation().getBlock().getType().equals(Material.WORKBENCH) && (!factoryExistsAt(production.getCenterLocation())) + || !factoryExistsAt(production.getInventoryLocation()) || !factoryExistsAt(production.getPowerSourceLocation())) + { + producers.add(production); + return new InteractionResponse(InteractionResult.SUCCESS, ""); + } + else + { + return new InteractionResponse(InteractionResult.FAILURE, ""); + } } public Factory getFactory(Location factoryLocation) { - // TODO Auto-generated method stub + for (Production production : producers) + { + if (production.getCenterLocation().equals(factoryLocation) || production.getInventory().equals(factoryLocation) + || production.getPowerSourceLocation().equals(factoryLocation)) + return production; + } return null; } public boolean factoryExistsAt(Location factoryLocation) { - // TODO Auto-generated method stub - return false; + return getFactory(factoryLocation) != null; } public void removeFactory(Factory factory) { - // TODO Auto-generated method stub - + producers.remove((Production)factory); } public String getSavesFileName() { - // TODO Auto-generated method stub - return null; + return FactoryModPlugin.PRODUCTION_SAVES_FILE; } } diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/properties/ProductionProperties.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/properties/ProductionProperties.java index 13dfd254c..a5c437bec 100644 --- a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/properties/ProductionProperties.java +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/properties/ProductionProperties.java @@ -6,8 +6,8 @@ import java.util.List; import org.bukkit.Material; +import com.github.igotyou.FactoryMod.interfaces.Properties; import com.github.igotyou.FactoryMod.recipes.ProductionRecipe; -import com.github.igotyou.interfaces.Properties; public class ProductionProperties implements Properties { diff --git a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java index 2d8967f1c..aa846c8b7 100644 --- a/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java +++ b/plugins/factorymod-paper/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java @@ -4,7 +4,7 @@ import java.util.HashMap; import org.bukkit.Material; -import com.github.igotyou.interfaces.Recipe; +import com.github.igotyou.FactoryMod.interfaces.Recipe; public class ProductionRecipe implements Recipe {