Solved My placeholders doesnt work!

Discussion in 'Plugin Development' started by kaaseigenaar, Jun 23, 2017.

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

    kaaseigenaar

    Hey, what do i wrong? This wil be reloaded my scoreboard plugin.


    Code:
      
     public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {    
         if(command.getLabel().equals("sbreload")) {
            saveConfig();
            reloadConfig();
            saveConfig();
             sender.sendMessage(ChatColor.GREEN + "Reloaded scoreboardplus config!");
     }
     return true;
    }
      
     
  2. Offline

    timtower Administrator Administrator Moderator

    @kaaseigenaar Don't call saveConfig in a reload, saveConfig will override the edited file.
     
  3. Offline

    kaaseigenaar

    Is this okay?

    Code:
      
     public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {    
         if(command.getLabel().equals("sbreload")) {
            getConfig().set("Lines", lines);
            reloadConfig();
             sender.sendMessage(ChatColor.GREEN + "Reloaded scoreboardplus config!");
     }
     return true;
    }
     
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    kaaseigenaar

    I want if i / sbreload do that then reload my entire configuration and put to the right right now it's only if I do / reload but i just want it in that plugin if you want i can also send the whole plugin code but that I do via private I do not want to make him public
     
  6. Offline

    timtower Administrator Administrator Moderator

    Trust me, nobody cares about it.
    And reloadConfig will reload your config just fine, no need to set anything.
     
  7. Offline

    kaaseigenaar

    Okay, thanks!
    I have one more question;
    How can i add the whole messages WITH spaces by the message here code:

    Message line code:
    Code:
     
                  sender.sendMessage(ChatColor.GREEN + "The line has been added successfully! Please wait 10 seconds then he is there! "
                    + ChatColor.DARK_RED + " Added: " + ChatColor.translateAlternateColorCodes('&',  (args[i] + "")));
    
    whole code:
    Code:
     
    public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {   
         if(command.getLabel().equals("sbaddline")) {
            if (sender.hasPermission("scoreboardplus.addline")) {
            if (args.length == 0) {
                sender.sendMessage("/sbaddline [Text]");
                return true;
            } else {
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < args.length; i++) {
                    builder.append(args[i] + " ");
                    sender.sendMessage(ChatColor.GREEN + "The line has been added successfully! Please wait 10 seconds then he is there! "
                    + ChatColor.DARK_RED + " Added: " + ChatColor.translateAlternateColorCodes('&',  (args[i] + "")));
                }
    
    This says he now:
    [​IMG]
    https://gyazo.com/4dfb50e8521d10837b5cbdfa327bd208
    ( this is 1 line like: "/sbaddline &a1 &b2 &c3 ")
     
  8. Offline

    timtower Administrator Administrator Moderator

    @kaaseigenaar Don't send the message in the loop, send it after the loop.
     
  9. Offline

    kaaseigenaar

    Do you know why my placeholders doesnt work?
    ( there is one more code ( The Main.java ) )
    Code:
     
    package me.kaaseigenaar.scorebaord;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Statistic;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    
    import me.clip.placeholderapi.PlaceholderAPI;
    
    public class ScoreboardBuilder {
      
        private static String replace(String s, Player p) {
            String l = s;
             Date now = new Date();
             SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
             SimpleDateFormat date = new SimpleDateFormat("dd-MM-yyyy");
            l.replaceAll("%player%", p.getPlayerListName())
             .replace("%online%", Bukkit.getOnlinePlayers().size() + "")
             .replace("%world%", Bukkit.getServer().getWorldType())
             .replace("%maxonline%", Bukkit.getServer().getMaxPlayers() + "")
             .replaceAll("%chestopen%", p.getStatistic(Statistic.CHEST_OPENED) + "" )
             .replaceAll("%damagedealt%", p.getStatistic(Statistic.DAMAGE_DEALT) + "")
             .replaceAll("%damagetaken%", p.getStatistic(Statistic.DAMAGE_TAKEN) + "")
             .replace("%gamemode%", p.getGameMode() + "")
             .replace("%health%", p.getHealth() + "")
             .replaceAll("%kills%", p.getStatistic(Statistic.PLAYER_KILLS) + "")
             .replace("%potion%", p.getActivePotionEffects() + "")
             .replaceAll("%deaths%", p.getStatistic(Statistic.DEATHS) + "")
             .replaceAll("%left%", p.getStatistic(Statistic.LEAVE_GAME) + "")
             .replace("%walkspeed%", p.getWalkSpeed() + "")
             .replace("%time%", time.format(now))
             .replaceAll("%jumps%", p.getStatistic(Statistic.JUMP) + "")
             .replace("%date%", date.format(now));
            return l;
        }
      
        public static void buildScoreboard(Player p) {
            //basis scoreboard
            Scoreboard score = Bukkit.getScoreboardManager().getNewScoreboard();
            final Objective objective = score.registerNewObjective("scoreboard", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(Main.plugin.getConfig().getString("Title").replaceAll("&", "§"));
            for (String s : Main.lines) {
                if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
                    String nieuw = PlaceholderAPI.setPlaceholders(p,  s);
                    objective.getScore(nieuw.replaceAll("&", "§") + " ").setScore(Main.lines.size() - Main.lines.indexOf(s));
                } else {
                    String nieuw = replace(s, p);
                    objective.getScore(nieuw.replaceAll("&", "§") + " ").setScore(Main.lines.size() - Main.lines.indexOf(s));
                }
            }
          
            p.setScoreboard(score);
        }
    
    }
    
      
     
    Last edited: Jun 24, 2017
  10. Offline

    Caderape2

    @kaaseigenaar You don't catch the return.
    The method replace() return a modified string, it don't modify the actual one.
     
  11. Offline

    kaaseigenaar

    How should I do it then?
    - Thomas
     
  12. Offline

    Caderape2

    Last edited: Jun 24, 2017
  13. Offline

    kaaseigenaar

    can you give one mini-example?
    - Thomas
     
  14. Offline

    Caderape2

    @kaaseigenaar
    Oh sorry,wrong post. forget about the path.

    Code:
    private static String replace(String s, Player p) {
            String l = s;
             Date now = new Date();
             SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
             SimpleDateFormat date = new SimpleDateFormat("dd-MM-yyyy");
            l = l.replaceAll("%player%", p.getPlayerListName())
             .replace("%online%", Bukkit.getOnlinePlayers().size() + "")
             .replace("%world%", Bukkit.getServer().getWorldType())
             .replace("%maxonline%", Bukkit.getServer().getMaxPlayers() + "")
             .replaceAll("%chestopen%", p.getStatistic(Statistic.CHEST_OPENED) + "" )
             .replaceAll("%damagedealt%", p.getStatistic(Statistic.DAMAGE_DEALT) + "")
             .replaceAll("%damagetaken%", p.getStatistic(Statistic.DAMAGE_TAKEN) + "")
             .replace("%gamemode%", p.getGameMode() + "")
             .replace("%health%", p.getHealth() + "")
             .replaceAll("%kills%", p.getStatistic(Statistic.PLAYER_KILLS) + "")
             .replace("%potion%", p.getActivePotionEffects() + "")
             .replaceAll("%deaths%", p.getStatistic(Statistic.DEATHS) + "")
             .replaceAll("%left%", p.getStatistic(Statistic.LEAVE_GAME) + "")
             .replace("%walkspeed%", p.getWalkSpeed() + "")
             .replace("%time%", time.format(now))
             .replaceAll("%jumps%", p.getStatistic(Statistic.JUMP) + "")
             .replace("%date%", date.format(now));
            return l;
        }
     
  15. Offline

    kaaseigenaar

    Where i need to insert the placeholder? like: " .replaceall("%player%", p.getplayerlistname())); "

    --
    for (String s : Main.lines) {
    if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
    String nieuw = PlaceholderAPI.setPlaceholders(p, s);
    objective.getScore(nieuw.replaceAll("&", "§") + " ").setScore(Main.lines.size() - Main.lines.indexOf(s));
    } else {
    String nieuw = replace(s, p);
    objective.getScore(nieuw.replaceAll("&", "§") + " ").setScore(Main.lines.size() - Main.lines.indexOf(s));
    }
    }
     
Thread Status:
Not open for further replies.

Share This Page