Looking for Assistance (free contribution)

Discussion in 'Spigot Plugin Development' started by lilsimmi, May 14, 2022.

  1. lilsimmi

    lilsimmi Previously Aslane02

    #1 lilsimmi, May 14, 2022
    Last edited: May 14, 2022
  2. A good start would be to post the code on GitHub or a similar platform, that way people can submit "pull requests" which, if you're not familiar, means people can edit their copy of the code, and then request that their changes be merged into your copy of the code.

    It seems that the plugin doesn't work properly though? I ran a decompiler on it and it produced this code:
    Code (Java):
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        String prefix = String.valueOf(ChatColor.BLUE.toString()) + ChatColor.BOLD.toString() + "Hits" + ChatColor.DARK_GRAY.toString() + ChatColor.BOLD.toString() + "> ";
        Player hitSender = (Player)sender;
        World world = Bukkit.getWorld("world");
        if (label.equals("hit") && args.length == 1 && sender.hasPermission("hits.hit")) {
            String targetName = args[0];
            hitSender.equals(targetName);
            world.spawnEntity(hitSender.getLocation(), EntityType.WITHER_SKELETON);
            world.spawnEntity(hitSender.getLocation(), EntityType.WITHER_SKELETON);
            world.spawnEntity(hitSender.getLocation(), EntityType.WITHER_SKELETON);
            hitSender.sendMessage(String.valueOf(prefix) + ChatColor.WHITE + "You've been hit by " + sender.getName().toString());
        }
        return true;
    }
    (Decompiling is only a rough approximation of the original code, so it probably isn't exactly how it looks in your IDE.) It looks like you never call Bukkit.getPlayer() or anything to get the target player, you just set it to the player who ran the command, meaning that the mobs only ever spawn on the player who ran the command. (The line hitSender.equals(targetName) doesn't do anything, it checks if a hitSender is equal to a string, which can never be true, but the return value is discarded anyway.)

    Instead, set hitSender to Bukkit.getPlayer(args[0]); which will get the player whose name was provided in the first command arg. Make sure you check args.length before you access args[0] though, and make sure you null check hitSender to make sure the command sender provided the name of a player that is actually online.

    It also only works if the world the player is in is named "world". Instead of getting the world named "world", just get the world the target player is in with hitSender.getWorld()
     
  3. lilsimmi

    lilsimmi Previously Aslane02

    I think I just fixed the issues with the plugin. Ill for sure post it on git hub.
     
  4. Cool, let me know when it's posted and I'll take a look :)
     
  5. lilsimmi

    lilsimmi Previously Aslane02

    posted right now, also added the github link in the original post
     
    #5 lilsimmi, May 14, 2022
    Last edited: May 14, 2022
    • Winner Winner x 1
  6. Don't know if you saw already but I opened a pull request this morning :)
     
  7. lilsimmi

    lilsimmi Previously Aslane02

    I got the plugin in game and it doesn't show up on /pl
    I just copy and pasted the code and fixed the errors
    Is there a way to download it from GitHub?
     
    #7 lilsimmi, May 16, 2022
    Last edited: May 16, 2022
  8. You'll just need to download the changed files, and copy them into your project (in the correct locations of course.)
     
  9. lilsimmi

    lilsimmi Previously Aslane02

    the code downloads as HTML so I just copy and pasted, and added vault. Still seems not too work :(
     
  10. What do you mean by it doesn't seem to work? Are there errors? And btw you can download a file by right clicking on the button that says "raw" and click save link as.
     
  11. lilsimmi

    lilsimmi Previously Aslane02

    No errors, Just doesn't show up in /pl. Im running 1.18.2
    Did you get it running?
     
  12. Use "git pull origin main" in your working directory
     
  13. Could you upload the build so I can check it out?
     
  14. lilsimmi

    lilsimmi Previously Aslane02

  15. yeah, the build would be helpful
     
  16. I'm guessing this new plugin you posted is the build you made, in which case the plugin.yml wasn't downloaded correctly. As you said, it downloads as HTML (if you just right-click in the file browser), so you have to either copy and paste or use the "raw" button.
     
  17. lilsimmi

    lilsimmi Previously Aslane02

    https://www.spigotmc.org/resources/mobsterhitstesting.102036/
    Just fixed it. Can somebody test it on multiplayer?
    https://www.spigotmc.org/resources/mobsterhitstesting.102036/
     
  18. lilsimmi

    lilsimmi Previously Aslane02

    Ive added messages telling the players what's happening