Solved Using replaceall for an int

Discussion in 'Plugin Development' started by javoris767, Dec 1, 2012.

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

    javoris767

    Hello, I'm trying to replace an it into %m in the config. Here is the code.

    Message Method
    Code:
        public static void sendCurrencyReveivedMessage(Player player, String playerName,
                String money)
        {
            String rawMessage = VoteSQLAPI.getConfigs()
                    .getConfig(VoteSQLConfFile.VOTESQLSETTINGS)
                    .getString("VoteSQL.currency.Message").toString();
            rawMessage = rawMessage.replace("%P", playerName.toLowerCase());
            rawMessage = rawMessage.replace("%M" , String.valueOf(money));
            String finalMessage = Functions.colorize(rawMessage);
            sendMessage(player, finalMessage);
        }
    Vault method
    Code:
        public static void addMoney(Player player, int money)
        {
            VoteSQLAPI.econ.depositPlayer(player.getName(), money);
        }
    When they are preformed
    Code:
            // Currency
            if(VoteSQLAPI.getConfigs().getConfig(VoteSQLConfFile.VOTESQLSETTINGS)
                    .getBoolean("VoteSQL.currency.Enabled") == true)
            {
                VoteSQLChat.sendCurrencyReveivedMessage(player, username, money);
                Functions.addMoney(player, VoteSQLAPI.getConfigs()
                        .getConfig(VoteSQLConfFile
                                .VOTESQLSETTINGS).getInt("VoteSQL.currency.Amount"));
            }
    In chat they it displays as javoris767, You received 0 dollars!
    In the config the default is 150.
    Thanks for helping :3
    P.S. The vault method works fine.
     
  2. Offline

    ron975

    money is a String
    You should have
    Code:java
    1. public static void sendCurrencyReveivedMessage(Player player, String playerName, int money)


    But you have
    Code:java
    1. public static void sendCurrencyReveivedMessage(Player player, String playerName, String money)

    Atleast, that's what I could pull, I'm in no means experienced :p
     
  3. Offline

    javoris767

    Changed it, its still 0 o-O

    Anything else o-O

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

    CeramicTitan

    Code:
    Quite a few things:
    rawMessage = rawMessage.replace("%M" , Integer.valueOf(money));
    public static void sendCurrencyReveivedMessage(Player player, String playerName, Integer money)
    I think that would work.
     
  5. Offline

    fireblast709

    Your config default must be set incorrect somewhere for 'VoteSQL.currency.Amount' as getInt("path") will return 0 if the path has not been found
    [additional commentary]
    ron975 CeramicTitan that parameter has nothing to do with being int, Integer or String otherwise his plugin would not compile, would it? He uses it in a message, so it is perfectly fine being a String
     
  6. Offline

    javoris767

    I got it working all good, but I'm getting 2 errors.

    me.javoris767.votesql.listeners.VotingListener.onVote(VotingListener.java:52)
    me.javoris767.votesql.utils.VoteSQLChat.sendCurrencyReveivedMessage(VoteSQLChat.java:91)

    Code:
        public static void sendCurrencyReveivedMessage(Player player, String playerName,
                int money)
        {
            String rawMessage = VoteSQLAPI.getConfigs()
                    .getConfig(VoteSQLConfFile.VOTESQLSETTINGS)
                    .getString("VoteSQL.currency.Message").toString();
            rawMessage = rawMessage.replace("%P", playerName.toLowerCase());
            rawMessage = rawMessage.replace("%M" , "" + money);
            String finalMessage = Functions.colorize(rawMessage);
      Line 91 ->      player.sendMessage(finalMessage);
        }
    Code:
            String username = vote.getUsername();
            Player player = Bukkit.getPlayer(username);
            int money = VoteSQLAPI.getConfigs()
                    .getConfig(VoteSQLConfFile.VOTESQLSETTINGS)
                    .getInt("VoteSQL.currency.Amount");
     
            // Currency
            if(VoteSQLAPI.getConfigs().getConfig(VoteSQLConfFile.VOTESQLSETTINGS)
                    .getBoolean("VoteSQL.currency.Enabled") == true)
            {
              Line 52 ->  VoteSQLChat.sendCurrencyReveivedMessage(player, username, money);
                Functions.addMoney(player, VoteSQLAPI.getConfigs()
                        .getConfig(VoteSQLConfFile
                                .VOTESQLSETTINGS).getInt("VoteSQL.currency.Amount"));
            }
     
  7. Offline

    CeramicTitan

    rawMessage = rawMessage.replace("%P", playerName.toLowerCase());
    rawMessage = rawMessage.replace("%M" , "" + money);
    rawMessage = Functions.colorize(rawMessage);
    player.sendMessage(rawMessage);
     
Thread Status:
Not open for further replies.

Share This Page