Fork?

Discussion in 'Spigot Plugin Development' started by Manish1267, Jun 11, 2017.

  1. Can someone fork this plugin? I'm no developers by any means but it looks pretty simple to fix. the problem is that when doing /block with iron ingots they turn into shears, or when doing it with gold ingots they turn into golden pants. it worked fine on 1.11.2 but not on 1.12.

    https://www.spigotmc.org/resources/blockcreator.3227/
     
  2. BTW the source code:
    Code (Text):
    package me.truetrojan.blockcreator;

    import me.truetrojan.blockcreator.utilities.BlockUtilities;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;

    public class BlockCreator
      extends JavaPlugin
    {
      public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
      {
        if (!(sender instanceof Player))
        {
          sender.sendMessage("This command is for players only!");
          return true;
        }
        Player player = (Player)sender;
        if (!player.hasPermission("blockcreator.use"))
        {
          player.sendMessage(ChatColor.RED + "You don't have permission.");
          return true;
        }
        ItemStack[] contents;
        int length = (contents = player.getInventory().getContents()).length;
        for (int i = 0; i < length; i++)
        {
          ItemStack stack = contents[i];
          if ((stack != null) && (BlockUtilities.isValid(stack.getType())) && (stack.getAmount() >= 4))
          {
            ItemStack blocks = BlockUtilities.getBlocks(stack);
            if (blocks != null)
            {
              ItemStack removeStack = stack.clone();
              removeStack.setAmount(BlockUtilities.recipeRequires(stack) * blocks.getAmount());
              player.getInventory().removeItem(new ItemStack[] { removeStack });
              player.getInventory().addItem(new ItemStack[] { blocks });
            }
          }
        }
        return true;
      }
    }
     
    Code (Text):

    package me.truetrojan.blockcreator.utilities;

    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.Recipe;
    import org.bukkit.inventory.ShapedRecipe;

    public class BlockUtilities
    {
      public static Material[] VALID_ITEMS = { Material.DIAMOND, Material.IRON_INGOT, Material.GOLD_INGOT, Material.COAL, Material.EMERALD, Material.INK_SACK, Material.QUARTZ, Material.REDSTONE, Material.WHEAT, Material.GLOWSTONE_DUST, Material.GOLD_NUGGET, Material.CLAY_BRICK, Material.MELON };
      public static boolean isValid(Material item)
      {
        return Arrays.asList(VALID_ITEMS).contains(item);
      }
      public static ItemStack getBlocks(ItemStack stack)
      {
        ShapedRecipe shapeRecipe = getRecipe(stack);
        if (shapeRecipe != null)
        {
          int requires = recipeRequires(stack);
          if (stack.getAmount() >= requires)
          {
            ItemStack result = shapeRecipe.getResult();
            result.setAmount(stack.getAmount() / requires);
            return result;
          }
        }
        return null;
      }
      public static int recipeRequires(ItemStack stack)
      {
        return getRecipe(stack).getIngredientMap().values().size();
      }
      private static ShapedRecipe getRecipe(ItemStack stack)
      {
        Iterator<Recipe> iter = Bukkit.recipeIterator();
        while (iter.hasNext())
        {
          Recipe recipe = (Recipe)iter.next();
          if ((recipe instanceof ShapedRecipe))
          {
            ShapedRecipe shapeRecipe = (ShapedRecipe)recipe;
            if ((getFirst(shapeRecipe.getIngredientMap().values()).getType() == stack.getType()) && (isBlock(shapeRecipe))) {
              return shapeRecipe;
            }
          }
        }
        return null;
      }
      private static boolean isBlock(ShapedRecipe recipe)
      {
        if ((recipe.getIngredientMap().values().size() != 4) && (recipe.getIngredientMap().values().size() != 9)) {
          return false;
        }
        boolean is = true;
        Material last = null;
        for (ItemStack i : recipe.getIngredientMap().values()) {
          if (i != null)
          {
            if (last == null) {
              last = i.getType();
            }
            if (last != i.getType()) {
              is = false;
            }
            last = i.getType();
          }
        }
        return is;
      }
      private static ItemStack getFirst(Collection<ItemStack> coll)
      {
        for (ItemStack i : coll) {
          if (i != null) {
            return i;
          }
        }
        return null;
      }
    }

     
     
  3. If I'm forking it, I need the GitHub (or git) :). I'm not gonna decompile and steal their code.
     
  4. True, I've messaged the author.
     
  5. They will most likely fix it themselves
     
  6. Hopefully, it hasn't been updated in more than a year