Do percent variables work with coding?

Discussion in 'Plugin Development' started by cmz1675, Jan 7, 2015.

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

    cmz1675

    Hi, I decided to make the economy dollars to tokens and i'm gonna create a plugin where you do /tokens and it will display tokens. If I do %econ_dollars% would that variable work? Thanks!
     
  2. Offline

    Skionz

  3. Offline

    cmz1675

    Thanks, worked.

    So I am at if(commandLabel.equalsIgnoreCase("tokens")){

    I am new to coding so I don't understand that code you gave me. Can you please put an example of a string of code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  4. Offline

    leon3001

  5. Offline

    JuicyDev

    In Bukkit you must first define your command in your plugin.yml under commands.

    Code:
    commands:
      yourcommandname:
        aliases: [alias1, alias2]
        description: A description of your command.
        usage: /<command> [your] [command] [usage]
        permission: my.command.permission
    The nodes on the command are optional however it helps the end user.

    Next, in your IDE you should create a new class for your command and have it implement CommandExecuter.

    Code:
    package your.package.name;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExectuter;
    import org.bukkit.command.CommandSender;
    
    public class CommandName implements CommandExecuter {
    
      public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        // Command functionality here
    
        return true;
      }
    
    }
    Next in your main class extending JavaPlugin, in the onEnable method you should add:

    Code:
    getCommand("yourcommandname").setExecuter(new CommandName())
    Note that in the setExecuter CommandName is the class you made for the command implementing CommandExecuter.

    Next in your CommandName class in the onCommand method you should add the functionality of the command.

    For example if your had the string:

    Code:
    String string = "Tokens: %econ_dollars%";
    If you then did:

    Code:
    int econDollars = 100; // Replace with suitable method for obtaining balance
    String result = string.replace("%econ_dollars%", econDollars);
    You would get the string "Tokens: 100" for the value of result.
     
    leon3001 likes this.
Thread Status:
Not open for further replies.

Share This Page