Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdo3D committed May 22, 2022
1 parent 2e9fd1a commit 5eab490
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 233 deletions.
95 changes: 65 additions & 30 deletions src/main/java/fr/birdo/endercargo/EnderCargo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package fr.birdo.endercargo;

import fr.birdo.endercargo.Utils.EnderCargoData;
import fr.birdo.endercargo.items.EnderCargoAdvancedOutput;
import fr.birdo.endercargo.items.EnderCargoInput;
import fr.birdo.endercargo.items.EnderCargoLinker;
import fr.birdo.endercargo.items.EnderCargoOutput;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
Expand All @@ -8,10 +13,13 @@
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Container;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.io.File;
import java.io.IOException;
Expand All @@ -24,47 +32,27 @@ public class EnderCargo extends JavaPlugin implements SlimefunAddon {
public void onEnable() {
getServer().getPluginManager().registerEvents(new EnderCargoInput(this), this);
getServer().getPluginManager().registerEvents(new EnderCargoOutput(this), this);
getServer().getPluginManager().registerEvents(new EnderCargoAdvancedOutput(this), this);
getServer().getPluginManager().registerEvents(new EnderCargoLinker(this), this);

/*
* 1. Creating a new Category
* This Category will use the following ItemStack
*/
//Creating a new category
ItemStack itemGroupItem = new CustomItemStack(Material.ENDER_EYE, "&5Ender Cargo", "", "&a> Click to open");

// Give your Category a unique id.
NamespacedKey itemGroupId = new NamespacedKey(this, "endercargo_category");
ItemGroup itemGroup = new ItemGroup(itemGroupId, itemGroupItem);

/*
* 2. Create a new SlimefunItemStack
* This class has many constructors, it is very important
* that you give each item a unique id.
*/
SlimefunItemStack ender_input = new SlimefunItemStack("ENDER_INPUT", Material.DISPENSER, EnderCargoInput.blockName, "&7Use the ender force to teleport", "&7items between worlds");
SlimefunItemStack ender_output = new SlimefunItemStack("ENDER_OUTPUT", Material.DISPENSER, EnderCargoOutput.blockName, "&7Use the ender force to teleport", "&7items between worlds");
SlimefunItemStack advanced_ender_output = new SlimefunItemStack("ADVANCED_ENDER_OUTPUT", Material.DISPENSER, EnderCargoAdvancedOutput.blockName, "&7Use the ender force to teleport", "&7items between worlds");
SlimefunItemStack ender_linker = new SlimefunItemStack("ENDER_LINKER", Material.ENDER_EYE, "&3Ender Cargo Linker", "&7&eShift + Right Click&7 to link", "&7&eLeft Click&7 to reset");
//Create Slimefun Itemstacks
SlimefunItemStack ender_input = new SlimefunItemStack("ENDER_INPUT", EnderCargoInput.blockMaterial, EnderCargoInput.blockName, "&7Use the ender force to teleport", "&7items between worlds");
SlimefunItemStack ender_output = new SlimefunItemStack("ENDER_OUTPUT", EnderCargoOutput.blockMaterial, EnderCargoOutput.blockName, "&7Use the ender force to teleport", "&7items between worlds");
SlimefunItemStack advanced_ender_output = new SlimefunItemStack("ADVANCED_ENDER_OUTPUT", EnderCargoAdvancedOutput.blockMaterial, EnderCargoAdvancedOutput.blockName, "&7Use the ender force to teleport", "&7items between worlds");
SlimefunItemStack ender_linker = new SlimefunItemStack("ENDER_LINKER", EnderCargoLinker.itemMaterial, EnderCargoLinker.itemName, "&7&eShift + Right Click&7 to link", "&7&eLeft Click&7 to reset");

/*
* 3. Creating a Recipe
* The Recipe is an ItemStack Array with a length of 9.
* It represents a Shaped Recipe in a 3x3 crafting grid.
* The machine in which this recipe is crafted in is specified
* further down as the RecipeType.
*/
//Creating Recipes
ItemStack[] ender_input_recipe = {null, SlimefunItems.INFUSED_HOPPER, null, SlimefunItems.ENDER_LUMP_3, SlimefunItems.CARGO_CONNECTOR_NODE, SlimefunItems.ENDER_LUMP_3, null, SlimefunItems.INFUSED_HOPPER, null};
ItemStack[] ender_output_recipe = {null, SlimefunItems.INFUSED_HOPPER, null, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.CARGO_CONNECTOR_NODE, SlimefunItems.MAGIC_LUMP_3, null, SlimefunItems.INFUSED_HOPPER, null};
ItemStack[] advanced_ender_output_recipe = {null, SlimefunItems.CARGO_MOTOR, null, SlimefunItems.REINFORCED_PLATE, ender_output, SlimefunItems.REINFORCED_PLATE, null, SlimefunItems.CARGO_MOTOR, null};
ItemStack[] ender_linker_recipe = {SlimefunItems.HARDENED_METAL_INGOT, SlimefunItems.ESSENCE_OF_AFTERLIFE, SlimefunItems.HARDENED_METAL_INGOT, SlimefunItems.HARDENED_METAL_INGOT, new ItemStack(Material.STICK), SlimefunItems.HARDENED_METAL_INGOT, null, new ItemStack(Material.STICK), null};

/*
* 4. Registering the Item
* Now you just have to register the item.
* RecipeType.ENHANCED_CRAFTING_TABLE refers to the machine in
* which this item is crafted in.
* Recipe Types from Slimefun itself will automatically add the recipe to that machine.
*/
//Registering Items
SlimefunItem ender_input_item = new SlimefunItem(itemGroup, ender_input, RecipeType.ENHANCED_CRAFTING_TABLE, ender_input_recipe);
ender_input_item.register(this);
SlimefunItem ender_output_item = new SlimefunItem(itemGroup, ender_output, RecipeType.ENHANCED_CRAFTING_TABLE, ender_output_recipe);
Expand All @@ -74,6 +62,7 @@ public void onEnable() {
SlimefunItem ender_linker_item = new SlimefunItem(itemGroup, ender_linker, RecipeType.ENHANCED_CRAFTING_TABLE, ender_linker_recipe);
ender_linker_item.register(this);

//Creating data file and folder
dataFolderPath = getDataFolder().getAbsolutePath();
File folder = new File(dataFolderPath);
if (!folder.exists())
Expand All @@ -86,8 +75,10 @@ public void onEnable() {
ex.printStackTrace();
}
}

//Run ticker
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
EnderCargoOutput.setContent();
setContent();
}, 0L, 1L);
}

Expand All @@ -111,4 +102,48 @@ public JavaPlugin getJavaPlugin() {
return this;
}

public void setContent() {
if (EnderCargoData.getLinkedCargo() != null) {
for (String string : EnderCargoData.getLinkedCargo()) {

String[] str = string.split(" ");
Location location = new Location(Bukkit.getWorld(str[0]), Integer.parseInt(str[1]), Integer.parseInt(str[2]), Integer.parseInt(str[3]));

Container outputContainer = (Container) location.getWorld().getBlockAt(location).getState();
ItemStack[] outputContent = outputContainer.getInventory().getStorageContents();

outputContainer.update();

BukkitRunnable task = new BukkitRunnable() {
@Override
public void run() {
if (location.getBlock().getType() == Material.DISPENSER && EnderCargoData.getInputCargo(location) != null && EnderCargoData.getInputCargo(location).getBlock().getType() == EnderCargoInput.blockMaterial) {

Container outputContainerTick = (Container) location.getWorld().getBlockAt(location).getState();
ItemStack[] outputContentTick = outputContainerTick.getInventory().getStorageContents();

Container inputContainer = (Container) EnderCargoData.getInputCargo(location).getWorld().getBlockAt(EnderCargoData.getInputCargo(location)).getState();
ItemStack[] inputContent = inputContainer.getInventory().getStorageContents();

for (int i = 0; i < 9; i++) {
int nb;
if (outputContent[i] != null) {
if (outputContentTick[i] == null) {
nb = outputContent[i].getAmount();
} else {
nb = outputContent[i].getAmount() - outputContentTick[i].getAmount();
}
ItemStack item = inputContent[i];
item.setAmount(inputContent[i].getAmount() - nb);
inputContainer.getInventory().setItem(i, item);
}
}
outputContainerTick.getInventory().setContents(inputContainer.getInventory().getContents());
}
}
};
task.runTaskLater(this, 1);
}
}
}
}

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/java/fr/birdo/endercargo/EnderCargoInput.java

This file was deleted.

166 changes: 0 additions & 166 deletions src/main/java/fr/birdo/endercargo/EnderCargoOutput.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.birdo.endercargo;
package fr.birdo.endercargo.Utils;

import fr.birdo.endercargo.EnderCargo;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
Expand Down
Loading

0 comments on commit 5eab490

Please sign in to comment.