Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NCBPFluffyBear committed Mar 1, 2024
1 parent 8f6bb4f commit 12197d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<dependency>
<groupId>io.github.TheBusyBiscuit</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-36</version>
<version>RC-37</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new KeyedCrafterListener(), this);

final Metrics metrics = new Metrics(this, 8927);

getLogger().log(Level.INFO, ChatColor.GREEN + "Hi there! Want to share your server with the " +
"Slimefun community?");
getLogger().log(Level.INFO, ChatColor.GREEN + "Join the official Slimefun Discord server at " +
"https://discord.gg/slimefun");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.ncbpfluffybear.fluffymachines.items.tools;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand All @@ -11,13 +13,9 @@
import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;
import io.github.thebusybiscuit.slimefun4.libraries.unirest.json.JSONObject;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.ncbpfluffybear.fluffymachines.FluffyMachines;
import io.ncbpfluffybear.fluffymachines.utils.Utils;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import org.bukkit.Bukkit;
Expand All @@ -33,6 +31,10 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

/**
* used to quickly manipulate cargo nodes
*
Expand All @@ -41,7 +43,7 @@
public class CargoManipulator extends SimpleSlimefunItem<ItemUseHandler> implements Listener {

private static final int[] CARGO_SLOTS = {19, 20, 21, 28, 29, 30, 37, 38, 39};
private Map<Player, Pair<JSONObject, ItemStack[]>> storedFilters = new HashMap<>();
private final Map<Player, Pair<JsonObject, ItemStack[]>> storedFilters = new HashMap<>();

public CargoManipulator(ItemGroup category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
Expand Down Expand Up @@ -102,7 +104,7 @@ private void onCargoManipulatorUse(PlayerInteractEvent e) {
*/
private void copyNode(Block parent, Player p, SlimefunItemStack nodeType) {
// Copy BlockStorage data
JSONObject nodeData = new JSONObject(BlockStorage.getBlockInfoAsJson(parent));
JsonObject nodeData = (JsonObject) new JsonParser().parse(BlockStorage.getBlockInfoAsJson(parent));

ItemStack[] filterItems = new ItemStack[9];
if (nodeType != SlimefunItems.CARGO_OUTPUT_NODE) { // No inventory
Expand All @@ -120,7 +122,7 @@ private void copyNode(Block parent, Player p, SlimefunItemStack nodeType) {

storedFilters.put(p, new Pair<>(nodeData, filterItems)); // Save cargo slots into map

Utils.send(p, "&aYour " + SlimefunItem.getById((String) nodeData.get("id")).getItemName() + " &ahas been copied.");
Utils.send(p, "&aYour " + SlimefunItem.getById(nodeData.get("id").getAsString()).getItemName() + " &ahas been copied.");
createParticle(parent, Color.fromRGB(255, 252, 51)); // Bright Yellow
}

Expand All @@ -129,7 +131,7 @@ private void copyNode(Block parent, Player p, SlimefunItemStack nodeType) {
* Action: Left Click
*/
private void pasteNode(Block child, Player p, SlimefunItemStack nodeType) {
Pair<JSONObject, ItemStack[]> nodeSettings = storedFilters.getOrDefault(p, null);
Pair<JsonObject, ItemStack[]> nodeSettings = storedFilters.getOrDefault(p, null);

// No data saved yet
if (nodeSettings == null) {
Expand All @@ -138,9 +140,9 @@ private void pasteNode(Block child, Player p, SlimefunItemStack nodeType) {
}

// Get saved data
JSONObject jsonData = nodeSettings.getFirstValue();
JsonObject jsonData = nodeSettings.getFirstValue();

SlimefunItemStack savedNodeType = (SlimefunItemStack) SlimefunItem.getById((String) jsonData.get("id")).getItem();
SlimefunItemStack savedNodeType = (SlimefunItemStack) SlimefunItem.getById(jsonData.get("id").getAsString()).getItem();
if (savedNodeType != nodeType) {
Utils.send(p, "&cYou copied a " + savedNodeType.getDisplayName() +
" &cbut you are trying to modify a " + nodeType.getDisplayName() + "&c!");
Expand Down

0 comments on commit 12197d3

Please sign in to comment.