Solved Miner's Torch Does Not Work at 1.15.2 (Source)

Discussion in 'Spigot Plugin Help' started by phrack_, May 8, 2020.

  1. https://www.spigotmc.org/resources/miners-torch.14827/ (the plugin in question)

    git-Paper-162 (MC: 1.15.2)
    In the Java 8 execution environment (jre1.8.0_241 ) ,
    A name problem occurred in the plugin.yml directory (can't be called).
    name: Miners torch
    name: Minerstorch (modified)
    Erase and name the space character in the above line.
    jar -cvf minerstiorch-1.0.jar *
    I solved it through this command (jdk1.8.0_251)

    Later, I was able to load this plugin successfully

    But..

    It doesn't work...

    Below is the source code for this plugin

    https://github.com/KernelFreeze/MinersTorch/tree/master/src/main/java/me/kernelfreeze/minerstorch
    Code (Text):
    package me.kernelfreeze.minerstorch;

    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.material.Torch;

    public class TorchListener
      implements Listener
    {
      private final MinersTorch plugin;
     
      public TorchListener(MinersTorch plugin)
      {
        this.plugin = plugin;
      }
     
      @EventHandler
      public void onPlayerInteract(PlayerInteractEvent event)
      {
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
        {
          Player player = event.getPlayer();
          switch (player.getItemInHand().getType())
          {
          case GOLD_PICKAXE:
          case IRON_PICKAXE:
          case STONE_PICKAXE:
          case WOOD_PICKAXE:
          case DIAMOND_PICKAXE:
            if (!player.hasPermission("minerstorch.place")) {
              return;
            }
            if (player.hasPermission("minerstorch.unlimited"))
            {
              BlockFace face = event.getBlockFace();
              Block block = event.getClickedBlock().getRelative(face);
              if (block.getType() != Material.AIR) {
                return;
              }
              Torch torch = new Torch();
              torch.setFacingDirection(face);
              player.playSound(block.getLocation(), Sound.DIG_WOOD, 10.0F, 1.0F);
             
              block.setTypeIdAndData(torch.getItemTypeId(), torch.getData(), true);
            }
            else if (player.getInventory().contains(Material.TORCH))
            {
              BlockFace face = event.getBlockFace();
              Block block = event.getClickedBlock().getRelative(face);
              if (block.getType() != Material.AIR) {
                return;
              }
              Torch torch = new Torch();
              torch.setFacingDirection(face);
             
              PlayerInventory inventory = player.getInventory();
              int slot = inventory.first(Material.TORCH);
              ItemStack stack = inventory.getItem(slot);
              if (stack.getAmount() < 1) {
                return;
              }
              if (stack.getAmount() <= 1) {
                inventory.remove(stack);
              } else {
                inventory.setItem(slot, new ItemStack(Material.TORCH, stack.getAmount() - 1));
              }
              player.playSound(block.getLocation(), Sound.DIG_WOOD, 10.0F, 1.0F);
              block.setTypeIdAndData(torch.getItemTypeId(), torch.getData(), true);
            }
            break;
          }
        }
      }
    }
    How can I modify and build to support the latest API?

    Or does a similar plugin or script exist?

    To modify and use this plugin
    I know I need to learn Java
    That's why I need someones help
     
    #1 phrack_, May 8, 2020
    Last edited: May 8, 2020
  2. Choco

    Moderator

    I will create a fork, update it and create a pull request for you. Doubtful that the author will compile and release it but I'd at least be willing to update. It's a quick fix.
     
  3. Thank you very much!!
    My worries have diminished
     
  4. Choco

    Moderator

    License is MIT so I'm permitted to distribute without source code (although the changes I made are open anyways and will be contributed upstream). Due to licensing, I can attach here safely for you to download and use :) This will support 1.13.2+ though won't work with netherite pickaxes in the upcoming 1.16 update - it will need another update at that time.

    Source is here for anybody interested (branch 1.13)
    (If it has been deleted, see upstream instead. This fork will be deleted if / when changes are merged)
     

    Attached Files:

    • Winner Winner x 2
  5. I love MIT license from today...

    And thank you very much!!!

    I will learn Java from today through this opportunity
     
    • Like Like x 1