Solved Proper plugin.yml configuration

Discussion in 'Plugin Development' started by K3RSH0K, Jun 7, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    K3RSH0K

    I think something is wrong with my yaml.
    Whatever command I name email will not run, rather it'll return the /email<recipient>
    I tested to make sure this was not a problem in my code by switching the names of the commands /mail and /email.
    Before I did this, email would not run, after, mail would not run.

    What am I doing wrong in my plugin.yml?

    Code:
    main: ygm.mail
    name: mail
    version: 0.4
    api-version: 1.15
    author: k3rsh0k
    description: ygm is a plugin that allows you to send mail to other players.
    commands:
      mail:
        description: Allows you to use the mail service.
        usage: /mail<recipiant>
      email:
        description: Allows you to use the email service.
        usage: /email<recipiant>
    
    My code:
    Code:
    
    package ygm;
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    public class mail_exec implements CommandExecutor {
        private final mail plugin;
    
        public mail_exec(mail plugin) {
            this.plugin = plugin;
        }
    
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("email")) {
                if(args[0].equalsIgnoreCase("help")) {
                    sender.sendMessage("~~~~~~~~~~~ MAIL HELP ~~~~~~~~~~~");
                    sender.sendMessage("");
                    sender.sendMessage("To send mail, use the command: /mail <player>");
                    sender.sendMessage("Mail takes time to send, the eq used to calculate send time is:");
                    sender.sendMessage("`distanceBetweenPlayers / 11.6`: 11.6 bps is twice is fast as you can run in minecraft.");
                    sender.sendMessage("The item(s) to be sent is whatever is in your hand when you run the command.");
                    sender.sendMessage("");
                }else{
                if (!(sender instanceof Player)) {
                    sender.sendMessage("This command can only be run by a player.");
                } else {
                    Player player = (Player) sender;
                    if (args.length > 1) {
                        sender.sendMessage("Too many arguments!");
                        return false;
                    }
                    if (args.length < 1) {
                        sender.sendMessage("You need to specify a recipient.");
                        return false;
                    }
    
                    Player target = (Bukkit.getServer().getPlayer(args[0]));
                    if (target == null) {
                        sender.sendMessage(args[0] + " is not online!");
                        return false;
                    }
    
                    if(player.getItemInHand().getType() != Material.AIR){
                        float distance = (float) player.getLocation().distance(target.getLocation());
                        PlayerInventory inventory = target.getInventory();
                        PlayerInventory reminventory = player.getInventory();
                        ItemStack itemstack = player.getItemInHand();
                        reminventory.remove(itemstack);
                        float delaytime = (float) (distance / 11.6);
                        int a = Math.round(delaytime);
                        sender.sendMessage("Sending item: "+distance+" blocks over "+ (a / 60) +" minutes!");
                        plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, newRunnable() {
                            @Override
                            public void run() {
                                inventory.addItem(itemstack);
                                target.sendMessage("You recived "+itemstack.toString()+" from "+sender.getName()+".");
                                sender.sendMessage("Thank you for using the mail system: "+target.getDisplayName()+" recived your "+ itemstack.toString() +"");
                            }
                        }, (int) (20*a));
                        returntrue;
                    }else{
                        sender.sendMessage("YOU CANNOT SEND AIR.");
                        returnfalse;
                    }
                }
                returntrue;
                }
            }else if (cmd.getName().equalsIgnoreCase("mail")) {
                if(args[0].equalsIgnoreCase("help")) {
                    sender.sendMessage("~~~~~~~~~~~ EMAIL HELP ~~~~~~~~~~~");
                    sender.sendMessage("");
                    sender.sendMessage("To send mail, use the command: /email <player>");
                    sender.sendMessage("Mail takes time to send, the eq used to calculate send time is:");
                    sender.sendMessage("`distanceBetweenPlayers / 11.6`: 11.6 bps is twice is fast as you can run in minecraft.");
                    sender.sendMessage("The item(s) to be sent is whatever is in your hand when you run the command.");
                    sender.sendMessage("");
                }else{
                if (!(sender instanceof Player)) {
                    sender.sendMessage("This command can only be run by a player.");
                } else {
                    Player player = (Player) sender;
                    if (args.length > 1) {
                        sender.sendMessage("Too many arguments!");
                        returnfalse;
                    }
                    if (args.length < 1) {
                        sender.sendMessage("You need to specify a recipient.");
                        return false;
                    }
                    Player target = (Bukkit.getServer().getPlayer(args[0]));
                    if (target == null) {
                        sender.sendMessage(args[0] + " is not online!");
                        return false;
                    }
                    if(player.getItemInHand().getType() != Material.AIR){
                        PlayerInventoryinventory = target.getInventory();
                        PlayerInventoryreminventory = player.getInventory();
                        reminventory.remove(Material.IRON_BARS);
                        sender.sendMessage("Thank you for using the email system, you item will send momentairly...");
                        ItemStackitemstack = player.getItemInHand();
                        reminventory.remove(itemstack);
                        inventory.addItem(itemstack);
                        target.sendMessage("You recived "+itemstack.toString()+" from "+sender.getName()+".");
                        sender.sendMessage("Thank you for using the email system: "+target.getDisplayName()+" recived your "+ itemstack.toString() +"");
                        return true;
                    }else{
                        sender.sendMessage("YOU CANNOT SEND AIR.");
                        return false;
                    }
                }
                return true;
                }
            return false;
            }
            sender.sendMessage("Unknown command.");
            return false;
        }
    }
    
    Code:
    package ygm;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    publicfinalclassmailextendsJavaPlugin {
    
        @Override
    
        publicvoidonEnable() {
    
            getLogger().info("[i] ygm has been enabled!");
    
            this.getCommand("mail").setExecutor(newmail_exec(this));
    
        }    
    
    }
    
    
    (sorry for all the missing spaces, i do not know why they are not there :/)
     
    Last edited: Jun 7, 2020
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    K3RSH0K

    I've added my code.
     
  4. Offline

    timtower Administrator Administrator Moderator

    You need to set the executor for both commands.
    Or use an alias.
     
  5. Offline

    K3RSH0K

    Alright, thank you.
     
Thread Status:
Not open for further replies.

Share This Page