One Player uses a Command for all?

Discussion in 'Plugin Development' started by FuZioN720, May 12, 2013.

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

    FuZioN720

    Hello, i thought i had my code right but i just tested and when one person on the server uses the command it uses it for everyone on the serve i don't know why this is happening can someone help thanks, here is my code:

    Code:
    package plugins.xxfuzion360xx.ScoreboardMOTD;
     
    import java.io.File;
    import java.io.IOException;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import plugins.xxfuzion360xx.ScoreboardMOTD.Metrics;
     
    public class ScoreboardMOTD extends JavaPlugin implements Listener{
     
        static boolean Time = true;
        static boolean TimeMessageOn = true;
        static String TimeMessage = null;
        static boolean ShowMessage = false;
        static long TimeAmount = 1200;
        static Plugin plugin = null;
        static boolean Show = false;
        static boolean update = true;
        static String prefix = ChatColor.GOLD + "[" + ChatColor.DARK_RED + "ScoreBoard MOTD" + ChatColor.GOLD + "]" + ChatColor.RESET;
     
        Logger log;
        ScoreboardManager manager;
        Scoreboard board;
        Objective objective;
     
        public void onEnable() {
            Show = false;
            ShowMessage = getConfig().getBoolean("scoreboard.ShowMessage");
            TimeMessage = getConfig().getString("Time.TimeMessage");
            TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
            Time = getConfig().getBoolean("Time.Time");
            TimeAmount = getConfig().getLong("Time.TimeAmount");
            Bukkit.getPluginManager().registerEvents(this, this);
            manager = Bukkit.getScoreboardManager();
            board = manager.getNewScoreboard();
            objective = board.registerNewObjective("MOTD", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            update = getConfig().getBoolean("Update");
            ConfigurationSection conf = getConfig();
            if (conf.getBoolean("update", true)) {
                new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
            }
            try {
                Metrics metrics = new Metrics(this);
                metrics.start();
                }
            catch (IOException e) {
                System.out.println("Error Submitting stats!");
            }
            plugin = this;
            this.log = getLogger();
            File f = new File(getDataFolder(), "config.yml");
            if(!f.exists()){
                this.log.info("No configuration file found, generating a new one");
                saveDefaultConfig();
                this.log.info("Config file saved.");
                }
     
            loadData();
     
            System.out.println("[ScoreBoard MOTD] Enabled!");
        }
     
        public static void loadData()
          {
            plugin.reloadConfig();
          }
     
        public void show(Player p) {
            if (Show == true){
                objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Title")));
                Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
                score.setScore(10);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
                score.setScore(9);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
                score.setScore(8);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
                score.setScore(7);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
                score.setScore(6);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
                score.setScore(5);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
                score.setScore(4);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
                score.setScore(3);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
                score.setScore(2);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
                score.setScore(1);
                p.setScoreboard(board);
                if (ShowMessage == true){
                    p.sendMessage(prefix + ChatColor.GOLD + " Score Board Shown");
                }
            } else if (Show == false){
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
                if (ShowMessage == true){
                    p.sendMessage(prefix + ChatColor.GOLD + " Score Board Hidden");
                }
            } else {
                p.sendMessage("Is this plugin broking?");
            }
        }
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player p = (Player)sender;
            if (command.getName().equalsIgnoreCase("Show") || (command.getName().equalsIgnoreCase("sbMOTdShow"))) {
                if (!p.hasPermission("sbmotd.show")) {
                      p.sendMessage(ChatColor.RED + "You do not have permission.");
                    } else {
                        Show = true;
                        show(p);
                    }
            }
            if (command.getName().equalsIgnoreCase("Hide") || (command.getName().equalsIgnoreCase("sbMOTdhide"))) {
                if (!p.hasPermission("sbmotd.hide")) {
                      p.sendMessage(ChatColor.RED + "You do not have permission.");
                    } else {
                        Show = false;
                        show(p);
                    }
            }
            if (command.getName().equalsIgnoreCase("sbreload") || (command.getName().equalsIgnoreCase("sbMOTdreload"))) {
                if (!p.hasPermission("sbmotd.reload")) {
                  p.sendMessage(ChatColor.RED + "You do not have permission.");
                } else {
                    Show = false;
                    show(p);
                    reloadConfig();
                    ShowMessage = getConfig().getBoolean("ScoreBoard.ShowMessage");
                    TimeMessage = getConfig().getString("Time.TimeMessage");
                    TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
                    Time = getConfig().getBoolean("Time.Time");
                    TimeAmount = getConfig().getLong("Time.TimeAmount");
                    update = getConfig().getBoolean("Update");
                    ConfigurationSection conf = getConfig();
                    if (conf.getBoolean("update", true)) {
                        new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
                    }
                    p.sendMessage(prefix + ChatColor.GREEN + " Config Realoaded");
                }
            }
            if (command.getName().equalsIgnoreCase("sbhelp") || (command.getName().equalsIgnoreCase("sbMOTdhelp"))) {
                if (!p.hasPermission("sbmotd.help")) {
                  p.sendMessage(ChatColor.RED + "You do not have permission.");
                } else if (args.length == 0) {
                    p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
                    p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
                    p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
                    p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
                } if (args[0].equalsIgnoreCase("1")) {
                    p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
                    p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
                    p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
                    p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
                } if (args[0].equalsIgnoreCase("2")) {
                    p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 2" + ChatColor.GRAY + "===---");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDShow " + ChatColor.RESET + "Shows the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDHide " + ChatColor.RESET + "Hides the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDReload " + ChatColor.RESET + "Reload the config.yml");
                }
                }return true;
            }
     
     
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            final Player p = event.getPlayer();
            Show = true;
            show(p);
            ConfigurationSection conf = getConfig();
            if (conf.getBoolean("update", true)) {
                new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
            }
            if (Time == true){
                this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        Show = false;
                        show(p);
                        if (TimeMessageOn == true){
                            p.sendMessage(TimeMessage);
                        } else if (TimeMessageOn == false){
                        }
                    }
                }, TimeAmount);// 60 L == 3 sec, 20 ticks == 1 sec
            }
        }
    }
     
    
    For Example: The score board would be showing then when my friend does /hide it hides my scoreboard, i don't know why.
     
  2. Offline

    RROD

    The problem you're facing here is that you're setting true for every player, okay. You're looking to set it up so every player is able to use /show individually, right?

    From here you will need to either look into using Player based Metadata (see the Q&A), or a HashMap<Player, Boolean>. You might want to do a bit of reading up about these.
     
  3. Offline

    FuZioN720

    RROD thats exactly what i want thanks ill look in to this.

    RROD Should i use HashMap<String, ArrayList<>> or HashMap<Player, ArrayList<>>

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

    RROD

    It's HashMap<Player, Boolean> if you want to use those.
    Then to get a variable from within a HashMap you can do map.get(Player)
    Also map.remove(Player)
    and map.put(Player, isShowing)
    Where map is your HashMap variable.

    Also you before you add or remove something, you'll want to check to see if the player is in the HashMap. You can do this with map.containsKey(Player)
     
  5. Offline

    FuZioN720

    RROD ok thanks. Also when i want to get the value do i use map.get(isShowing)?
     
  6. Offline

    RROD

    map.get(Player) should be it. If not it's map.getValue(Player)
    That will return the boolean isShowing
    I'm not near my machine so I couldn't say.
     
  7. Offline

    FuZioN720

    RROD Ok so i have two vaules isShowing, = true and notShowing, = false

    Now i want it so if the player has isShowing to Show the scoreboard and if the player has notShowing to hide the screobaord. Here is the code that im using to do this but its not working.

    Code:
    if(map.get(Player)){
        if(map.getValue(isShowing)){
            //Scoreboard code here to show
        } else if(map.getValue(notShowing)){
            //Scoreboard code here to hide
        }
    }
    I'm getting an error on the getValue in eclipse i don't think i can use getValue

    Or Should i just use if in the hashmap then show the scorebaord and if not in the hashmap hide the scroebaord?
    RROD

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

    ferrybig

    its not smart to use a Player object as a key of a hashmap, use its name, see my signature for details
     
    RROD likes this.
  9. Offline

    FuZioN720

    ferrybig i see. If i use HashMap<String, Boolean> how can i make the string the player's name. Will i have to create a String = player.getname

    Can anyone help me i think i fix the hashmap but now im getting an error heres my code and error:

    Main:
    Code:
    package plugins.xxfuzion360xx.ScoreboardMOTD;
     
    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import plugins.xxfuzion360xx.ScoreboardMOTD.Metrics;
     
    public class ScoreboardMOTD extends JavaPlugin implements Listener{
     
        static Boolean isShowing = true;
        static boolean Time = true;
        static boolean TimeMessageOn = true;
        static String TimeMessage = null;
        static boolean ShowMessage = false;
        static long TimeAmount = 1200;
        static Plugin plugin = null;
        static boolean Show = false;
        static boolean update = true;
        static String prefix = ChatColor.GOLD + "[" + ChatColor.DARK_RED + "ScoreBoard MOTD" + ChatColor.GOLD + "]" + ChatColor.RESET;
        public final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
     
        Logger log;
        ScoreboardManager manager;
        Scoreboard board;
        Objective objective;
       
        public void onEnable() {
            Show = false;
            ShowMessage = getConfig().getBoolean("scoreboard.ShowMessage");
            TimeMessage = getConfig().getString("Time.TimeMessage");
            TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
            Time = getConfig().getBoolean("Time.Time");
            TimeAmount = getConfig().getLong("Time.TimeAmount");
            Bukkit.getPluginManager().registerEvents(this, this);
            manager = Bukkit.getScoreboardManager();
            board = manager.getNewScoreboard();
            objective = board.registerNewObjective("MOTD", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            update = getConfig().getBoolean("Update");
            ConfigurationSection conf = getConfig();
            if (conf.getBoolean("update", true)) {
                new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
            }
            try {
                Metrics metrics = new Metrics(this);
                metrics.start();
                }
            catch (IOException e) {
                System.out.println("Error Submitting stats!");
            }
            plugin = this;
            this.log = getLogger();
            File f = new File(getDataFolder(), "config.yml");
            if(!f.exists()){
                this.log.info("No configuration file found, generating a new one");
                saveDefaultConfig();
                this.log.info("Config file saved.");
                }
     
            loadData();
     
            System.out.println("[ScoreBoard MOTD] Enabled!");
        }
     
        public static void loadData()
          {
            plugin.reloadConfig();
          }
       
        public void show(Player p) {
            String playerName = p.getName();
            if (map.get(playerName)){
                objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Title")));
                Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
                score.setScore(10);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
                score.setScore(9);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
                score.setScore(8);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
                score.setScore(7);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
                score.setScore(6);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
                score.setScore(5);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
                score.setScore(4);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
                score.setScore(3);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
                score.setScore(2);
                score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
                score.setScore(1);
                p.setScoreboard(board);
                if (ShowMessage == true){
                    p.sendMessage(prefix + ChatColor.GOLD + " Score Board Shown");
                }
            } else {
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
                board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
                if (ShowMessage == true){
                    p.sendMessage(prefix + ChatColor.GOLD + " Score Board Hidden");
                }
            }
        }
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player p = (Player)sender;
            String playerName = p.getName();
            if (command.getName().equalsIgnoreCase("Show") || (command.getName().equalsIgnoreCase("sbMOTdShow"))) {
                if (!p.hasPermission("sbmotd.show")) {
                      p.sendMessage(ChatColor.RED + "You do not have permission.");
                    } else {
                        if (!map.containsKey(playerName)){
                        map.put(playerName, isShowing);
                        }
                        if (map.get(playerName)){
                            show(p);
                        } else {
                            show(p);
                        }
                        map.put(playerName, isShowing);
                    }
            }
            if (command.getName().equalsIgnoreCase("Hide") || (command.getName().equalsIgnoreCase("sbMOTdhide"))) {
                if (!p.hasPermission("sbmotd.hide")) {
                      p.sendMessage(ChatColor.RED + "You do not have permission.");
                    } else {
                        if (map.containsKey(playerName)){
                        map.remove(playerName);
                    }
                        if (map.get(playerName)){
                            show(p);
                        } else {
                            show(p);
                        }
                    }
            }
            if (command.getName().equalsIgnoreCase("sbreload") || (command.getName().equalsIgnoreCase("sbMOTdreload"))) {
                if (!p.hasPermission("sbmotd.reload")) {
                  p.sendMessage(ChatColor.RED + "You do not have permission.");
                } else {
                    reloadConfig();
                    ShowMessage = getConfig().getBoolean("ScoreBoard.ShowMessage");
                    TimeMessage = getConfig().getString("Time.TimeMessage");
                    TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
                    Time = getConfig().getBoolean("Time.Time");
                    TimeAmount = getConfig().getLong("Time.TimeAmount");
                    update = getConfig().getBoolean("Update");
                    ConfigurationSection conf = getConfig();
                    if (conf.getBoolean("update", true)) {
                        new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
                    }
                    p.sendMessage(prefix + ChatColor.GREEN + " Config Realoaded");
                }
            }
            if (command.getName().equalsIgnoreCase("sbhelp") || (command.getName().equalsIgnoreCase("sbMOTdhelp"))) {
                if (!p.hasPermission("sbmotd.help")) {
                  p.sendMessage(ChatColor.RED + "You do not have permission.");
                } else if (args.length == 0) {
                    p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
                    p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
                    p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
                    p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
                } if (args[0].equalsIgnoreCase("1")) {
                    p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
                    p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
                    p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
                    p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
                } if (args[0].equalsIgnoreCase("2")) {
                    p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 2" + ChatColor.GRAY + "===---");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDShow " + ChatColor.RESET + "Shows the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDHide " + ChatColor.RESET + "Hides the MOTD Score Board");
                    p.sendMessage(ChatColor.GREEN + "/SBMOTDReload " + ChatColor.RESET + "Reload the config.yml");
                }
                }return true;
            }
     
     
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            final Player p = event.getPlayer();
            final String playerName = p.getName();
            if (!map.containsKey(playerName)){
            map.put(playerName, isShowing);
            }
            if (map.get(playerName)){
                show(p);
            } else {
                show(p);
            }
            ConfigurationSection conf = getConfig();
            if (conf.getBoolean("update", true)) {
                new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
            }
            if (Time == true){
                this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        if (map.get(playerName)){
                            show(p);
                        } else {
                            show(p);
                        }
                        if (TimeMessageOn == true){
                            p.sendMessage(TimeMessage);
                        } else if (TimeMessageOn == false){
                        }
                    }
                }, TimeAmount);// 60 L == 3 sec, 20 ticks == 1 sec
            }
        }
    }
     
    
    Error:
    Code:
    21:54:56 [INFO] xXFuZioN360Xx issued server command: /hide
    21:54:56 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'hide
    ' in plugin ScoreboardMOTD v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    9)
            at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:965)
            at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.j
    ava:883)
            at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java
    :840)
            at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
            at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292
    )
            at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java
    :109)
            at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:5
    81)
            at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:4
    77)
            at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java
    :410)
            at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:5
    73)
    Caused by: java.lang.NullPointerException
            at plugins.xxfuzion360xx.ScoreboardMOTD.ScoreboardMOTD.onCommand(Scorebo
    ardMOTD.java:156)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 15 more
    >
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  10. Offline

    ferrybig

    plz change [.code][/code] to [.syntax][/syntax] so we see lines or read the stack trace by yourself and give the line with the error too
     
  11. Offline

    FuZioN720

    ferrybig i'm really bad at reading errors, but it happens when i use the /hide or /show command

    Main:
    Code:java
    1.  
    2. package plugins.xxfuzion360xx.ScoreboardMOTD;
    3.  
    4. import java.io.File;
    5. import java.io.IOException;
    6. import java.util.HashMap;
    7. import java.util.logging.Logger;
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.configuration.ConfigurationSection;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.player.PlayerJoinEvent;
    17. import org.bukkit.plugin.Plugin;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19. import org.bukkit.scoreboard.DisplaySlot;
    20. import org.bukkit.scoreboard.Objective;
    21. import org.bukkit.scoreboard.Score;
    22. import org.bukkit.scoreboard.Scoreboard;
    23. import org.bukkit.scoreboard.ScoreboardManager;
    24. import plugins.xxfuzion360xx.ScoreboardMOTD.Metrics;
    25.  
    26. public class ScoreboardMOTD extends JavaPlugin implements Listener{
    27.  
    28. static Boolean isShowing = true;
    29. static boolean Time = true;
    30. static boolean TimeMessageOn = true;
    31. static String TimeMessage = null;
    32. static boolean ShowMessage = false;
    33. static long TimeAmount = 1200;
    34. static Plugin plugin = null;
    35. static boolean Show = false;
    36. static boolean update = true;
    37. static String prefix = ChatColor.GOLD + "[" + ChatColor.DARK_RED + "ScoreBoard MOTD" + ChatColor.GOLD + "]" + ChatColor.RESET;
    38. public final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
    39.  
    40. Logger log;
    41. ScoreboardManager manager;
    42. Scoreboard board;
    43. Objective objective;
    44.  
    45. public void onEnable() {
    46. Show = false;
    47. ShowMessage = getConfig().getBoolean("scoreboard.ShowMessage");
    48. TimeMessage = getConfig().getString("Time.TimeMessage");
    49. TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
    50. Time = getConfig().getBoolean("Time.Time");
    51. TimeAmount = getConfig().getLong("Time.TimeAmount");
    52. Bukkit.getPluginManager().registerEvents(this, this);
    53. manager = Bukkit.getScoreboardManager();
    54. board = manager.getNewScoreboard();
    55. objective = board.registerNewObjective("MOTD", "dummy");
    56. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    57. update = getConfig().getBoolean("Update");
    58. ConfigurationSection conf = getConfig();
    59. if (conf.getBoolean("update", true)) {
    60. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    61. }
    62. try {
    63. Metrics metrics = new Metrics(this);
    64. metrics.start();
    65. }
    66. catch (IOException e) {
    67. System.out.println("Error Submitting stats!");
    68. }
    69. plugin = this;
    70. this.log = getLogger();
    71. File f = new File(getDataFolder(), "config.yml");
    72. if(!f.exists()){
    73. this.log.info("No configuration file found, generating a new one");
    74. saveDefaultConfig();
    75. this.log.info("Config file saved.");
    76. }
    77.  
    78. loadData();
    79.  
    80. System.out.println("[ScoreBoard MOTD] Enabled!");
    81. }
    82.  
    83. public static void loadData()
    84. {
    85. plugin.reloadConfig();
    86. }
    87.  
    88. public void show(Player p) {
    89. String playerName = p.getName();
    90. if (map.get(playerName)){
    91. objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Title")));
    92. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
    93. score.setScore(10);
    94. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
    95. score.setScore(9);
    96. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
    97. score.setScore(8);
    98. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
    99. score.setScore(7);
    100. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
    101. score.setScore(6);
    102. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
    103. score.setScore(5);
    104. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
    105. score.setScore(4);
    106. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
    107. score.setScore(3);
    108. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
    109. score.setScore(2);
    110. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
    111. score.setScore(1);
    112. p.setScoreboard(board);
    113. if (ShowMessage == true){
    114. p.sendMessage(prefix + ChatColor.GOLD + " Score Board Shown");
    115. }
    116. } else {
    117. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
    118. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
    119. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
    120. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
    121. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
    122. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
    123. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
    124. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
    125. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
    126. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
    127. if (ShowMessage == true){
    128. p.sendMessage(prefix + ChatColor.GOLD + " Score Board Hidden");
    129. }
    130. }
    131. }
    132. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    133. Player p = (Player)sender;
    134. String playerName = p.getName();
    135. if (command.getName().equalsIgnoreCase("Show") || (command.getName().equalsIgnoreCase("sbMOTdShow"))) {
    136. if (!p.hasPermission("sbmotd.show")) {
    137. p.sendMessage(ChatColor.RED + "You do not have permission.");
    138. } else {
    139. if (!map.containsKey(playerName)){
    140. map.put(playerName, isShowing);
    141. }
    142. if (map.get(playerName)){
    143. show(p);
    144. } else {
    145. show(p);
    146. }
    147. map.put(playerName, isShowing);
    148. }
    149. }
    150. if (command.getName().equalsIgnoreCase("Hide") || (command.getName().equalsIgnoreCase("sbMOTdhide"))) {
    151. if (!p.hasPermission("sbmotd.hide")) {
    152. p.sendMessage(ChatColor.RED + "You do not have permission.");
    153. } else {
    154. if (map.containsKey(playerName)){
    155. map.remove(playerName);
    156. }
    157. if (map.get(playerName)){
    158. show(p);
    159. } else {
    160. show(p);
    161. }
    162. }
    163. }
    164. if (command.getName().equalsIgnoreCase("sbreload") || (command.getName().equalsIgnoreCase("sbMOTdreload"))) {
    165. if (!p.hasPermission("sbmotd.reload")) {
    166. p.sendMessage(ChatColor.RED + "You do not have permission.");
    167. } else {
    168. reloadConfig();
    169. ShowMessage = getConfig().getBoolean("ScoreBoard.ShowMessage");
    170. TimeMessage = getConfig().getString("Time.TimeMessage");
    171. TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
    172. Time = getConfig().getBoolean("Time.Time");
    173. TimeAmount = getConfig().getLong("Time.TimeAmount");
    174. update = getConfig().getBoolean("Update");
    175. ConfigurationSection conf = getConfig();
    176. if (conf.getBoolean("update", true)) {
    177. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    178. }
    179. p.sendMessage(prefix + ChatColor.GREEN + " Config Realoaded");
    180. }
    181. }
    182. if (command.getName().equalsIgnoreCase("sbhelp") || (command.getName().equalsIgnoreCase("sbMOTdhelp"))) {
    183. if (!p.hasPermission("sbmotd.help")) {
    184. p.sendMessage(ChatColor.RED + "You do not have permission.");
    185. } else if (args.length == 0) {
    186. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
    187. p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    188. p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
    189. p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
    190. p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
    191. p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
    192. } if (args[0].equalsIgnoreCase("1")) {
    193. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
    194. p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    195. p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
    196. p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
    197. p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
    198. p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
    199. } if (args[0].equalsIgnoreCase("2")) {
    200. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 2" + ChatColor.GRAY + "===---");
    201. p.sendMessage(ChatColor.GREEN + "/SBMOTDHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    202. p.sendMessage(ChatColor.GREEN + "/SBMOTDShow " + ChatColor.RESET + "Shows the MOTD Score Board");
    203. p.sendMessage(ChatColor.GREEN + "/SBMOTDHide " + ChatColor.RESET + "Hides the MOTD Score Board");
    204. p.sendMessage(ChatColor.GREEN + "/SBMOTDReload " + ChatColor.RESET + "Reload the config.yml");
    205. }
    206. }return true;
    207. }
    208.  
    209.  
    210. @EventHandler
    211. public void onPlayerJoin(PlayerJoinEvent event) {
    212. final Player p = event.getPlayer();
    213. final String playerName = p.getName();
    214. if (!map.containsKey(playerName)){
    215. map.put(playerName, isShowing);
    216. }
    217. if (map.get(playerName)){
    218. show(p);
    219. } else {
    220. show(p);
    221. }
    222. ConfigurationSection conf = getConfig();
    223. if (conf.getBoolean("update", true)) {
    224. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    225. }
    226. if (Time == true){
    227. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    228. public void run() {
    229. if (map.get(playerName)){
    230. show(p);
    231. } else {
    232. show(p);
    233. }
    234. if (TimeMessageOn == true){
    235. p.sendMessage(TimeMessage);
    236. } else if (TimeMessageOn == false){
    237. }
    238. }
    239. }, TimeAmount);// 60 L == 3 sec, 20 ticks == 1 sec
    240. }
    241. }
    242. }
    243.  
    244.  


    Error:
    Code:text
    1.  
    2. 21:54:56 [INFO] xXFuZioN360Xx issued server command: /hide
    3. 21:54:56 [SEVERE] null
    4. org.bukkit.command.CommandException: Unhandled exception executing command 'hide
    5. ' in plugin ScoreboardMOTD v1.0
    6. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    7. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    8. 9)
    9. at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServe
    10. r.java:523)
    11. at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerCon
    12. nection.java:965)
    13. at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.j
    14. ava:883)
    15. at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java
    16. :840)
    17. at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
    18. at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292
    19. )
    20. at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java
    21. :109)
    22. at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
    23. at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:3
    24. 0)
    25. at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:5
    26. 81)
    27. at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:2
    28. 26)
    29. at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:4
    30. 77)
    31. at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java
    32. :410)
    33. at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:5
    34. 73)
    35. Caused by: java.lang.NullPointerException
    36. at plugins.xxfuzion360xx.ScoreboardMOTD.ScoreboardMOTD.onCommand(Scorebo
    37. ardMOTD.java:156)
    38. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    39. ... 15 more
    40. >
     
  12. Offline

    ferrybig

    you error doesn't fit your code,
    the error point to } what can give a error, maybe some enters to much or less at the start of the code, that caused this
    can you read the stack trace inside your ide using the following tutorial:
    http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/

    Notice, your plugin may not be approved at bukkitdev unless you dont make the automatic updater update without chancing a config node
     
  13. Offline

    thecrystalflame

    When reading an error look for the Caused By: java.something line.
    in your case:
    Code:text
    1. Caused by: java.lang.NullPointerException

    the next line shows where it is being caused.

    Code:text
    1. at plugins.xxfuzion360xx.ScoreboardMOTD.ScoreboardMOTD.onCommand(Scorebo
    2.  
    3. ardMOTD.java:156)

    in this case your line is

    Code:text
    1. if (map.get(playerName)){

    it is a NullPointerException which means it either isn't returning a value or playerName is null .

    Not that sure of what im seeing here. code for your Hide command
    Code:text
    1. if (map.containsKey(playerName)){
    2. map.remove(playerName);
    3. }
    4. if (map.get(playerName)){
    5. show(p);
    6. } else {
    7. show(p);
    8. }

    it seems you are removing the player from the map, then trying to get the player from the map. the reason you are getting a null pointer exception is because the player no longer exists inside it.

    try changing it to this:
    Code:text
    1. if (map.containsKey(playerName)){
    2. if (map.get(playerName)){
    3. show(p);//not sure why you want to call the show method for hide
    4. map.remove(playerName);
    5. } else {
    6. show(p);//again :|
    7. }
     
    russjr08 likes this.
  14. Offline

    gomeow

    Why not use an ArrayList of names, check if the list contains or doesn't contain the player's name
     
  15. Offline

    FuZioN720

    thecrystalflame The show method has the hide and show in it i had it before so that when false the scoreboard would be removed and if true then the scoreboard would be added so instead of making two methods i tryed to make one and check if something is false.

    gomeow How can i achieve this, please can you give code?

    Ok all i have the error fix thanks to thecrystalflame for the help and ferrybig for the link on how to read errors i can fix my errors, but now i have anyone problem ever time i use a command nothing is happening. i thought i have my code right but its not working here is my new code:

    Code:java
    1.  
    2. package plugins.xxfuzion360xx.ScoreboardMOTD;
    3.  
    4. import java.io.File;
    5. import java.io.IOException;
    6. import java.util.HashMap;
    7. import java.util.logging.Logger;
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.configuration.ConfigurationSection;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.player.PlayerJoinEvent;
    17. import org.bukkit.plugin.Plugin;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19. import org.bukkit.scoreboard.DisplaySlot;
    20. import org.bukkit.scoreboard.Objective;
    21. import org.bukkit.scoreboard.Score;
    22. import org.bukkit.scoreboard.Scoreboard;
    23. import org.bukkit.scoreboard.ScoreboardManager;
    24. import plugins.xxfuzion360xx.ScoreboardMOTD.Metrics;
    25.  
    26. public class ScoreboardMOTD extends JavaPlugin implements Listener{
    27.  
    28. static Boolean isShowing = true;
    29. static boolean Time = true;
    30. static boolean TimeMessageOn = true;
    31. static String TimeMessage = null;
    32. static boolean ShowMessage = false;
    33. static long TimeAmount = 1200;
    34. static Plugin plugin = null;
    35. static boolean Show = false;
    36. static boolean update = true;
    37. static String prefix = ChatColor.GOLD + "[" + ChatColor.DARK_RED + "ScoreBoard MOTD" + ChatColor.GOLD + "]" + ChatColor.RESET;
    38. public final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
    39.  
    40. Logger log;
    41. ScoreboardManager manager;
    42. Scoreboard board;
    43. Objective objective;
    44.  
    45. public void onEnable() {
    46. Show = false;
    47. ShowMessage = getConfig().getBoolean("scoreboard.ShowMessage");
    48. TimeMessage = getConfig().getString("Time.TimeMessage");
    49. TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
    50. Time = getConfig().getBoolean("Time.Time");
    51. TimeAmount = getConfig().getLong("Time.TimeAmount");
    52. Bukkit.getPluginManager().registerEvents(this, this);
    53. manager = Bukkit.getScoreboardManager();
    54. board = manager.getNewScoreboard();
    55. objective = board.registerNewObjective("MOTD", "dummy");
    56. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    57. update = getConfig().getBoolean("Update");
    58. ConfigurationSection conf = getConfig();
    59. if (conf.getBoolean("update") == true) {
    60. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    61. }
    62. try {
    63. Metrics metrics = new Metrics(this);
    64. metrics.start();
    65. }
    66. catch (IOException e) {
    67. System.out.println("Error Submitting stats!");
    68. }
    69. plugin = this;
    70. this.log = getLogger();
    71. File f = new File(getDataFolder(), "config.yml");
    72. if(!f.exists()){
    73. this.log.info("No configuration file found, generating a new one");
    74. saveDefaultConfig();
    75. this.log.info("Config file saved.");
    76. }
    77.  
    78. loadData();
    79.  
    80. System.out.println("[ScoreBoard MOTD] Enabled!");
    81. }
    82.  
    83. public static void loadData()
    84. {
    85. plugin.reloadConfig();
    86. }
    87.  
    88. public void hide (Player p){
    89. String playerName = p.getName();
    90. if (!map.get(playerName)){
    91. map.put(playerName, isShowing);
    92. hide(p);
    93. } else if (map.get(playerName)) {
    94. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
    95. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
    96. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
    97. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
    98. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
    99. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
    100. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
    101. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
    102. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
    103. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
    104. if (ShowMessage == true){
    105. p.sendMessage(prefix + ChatColor.GOLD + " Score Board Hidden");
    106. }
    107. map.remove(playerName);
    108. }
    109. }
    110.  
    111. public void show(Player p) {
    112. String playerName = p.getName();
    113. if (!map.get(playerName)){
    114. map.put(playerName, isShowing);
    115. show(p);
    116. } else if (map.get(playerName)) {
    117. objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Title")));
    118. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
    119. score.setScore(10);
    120. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
    121. score.setScore(9);
    122. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
    123. score.setScore(8);
    124. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
    125. score.setScore(7);
    126. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
    127. score.setScore(6);
    128. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
    129. score.setScore(5);
    130. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
    131. score.setScore(4);
    132. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
    133. score.setScore(3);
    134. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
    135. score.setScore(2);
    136. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
    137. score.setScore(1);
    138. p.setScoreboard(board);
    139. if (ShowMessage == true){
    140. p.sendMessage(prefix + ChatColor.GOLD + " Score Board Shown");
    141. }
    142. }
    143. }
    144. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    145. Player p = (Player)sender;
    146. String playerName = p.getName();
    147. if (command.getName().equalsIgnoreCase("Show") || (command.getName().equalsIgnoreCase("sbMOTdShow"))) {
    148. if (!p.hasPermission("sbmotd.show")) {
    149. p.sendMessage(ChatColor.RED + "You do not have permission.");
    150. } else {
    151. if (!map.containsKey(playerName)){
    152. map.put(playerName, isShowing);
    153. show(p);
    154. } else if (map.get(playerName)){
    155. show(p);
    156. }
    157. }
    158. if (command.getName().equalsIgnoreCase("Hide") || (command.getName().equalsIgnoreCase("sbMOTdhide"))) {
    159. if (!p.hasPermission("sbmotd.hide")) {
    160. p.sendMessage(ChatColor.RED + "You do not have permission.");
    161. } else {
    162. if (map.containsKey(playerName)){
    163. hide(p);
    164. } else if (!map.get(playerName)){
    165. map.put(playerName, isShowing);
    166. hide(p);
    167. }
    168. }
    169. }
    170. if (command.getName().equalsIgnoreCase("sbreload") || (command.getName().equalsIgnoreCase("sbMOTdreload"))) {
    171. if (!p.hasPermission("sbmotd.reload")) {
    172. p.sendMessage(ChatColor.RED + "You do not have permission.");
    173. } else {
    174. reloadConfig();
    175. ShowMessage = getConfig().getBoolean("ScoreBoard.ShowMessage");
    176. TimeMessage = getConfig().getString("Time.TimeMessage");
    177. TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
    178. Time = getConfig().getBoolean("Time.Time");
    179. TimeAmount = getConfig().getLong("Time.TimeAmount");
    180. update = getConfig().getBoolean("Update");
    181. ConfigurationSection conf = getConfig();
    182. if (conf.getBoolean("update", true)) {
    183. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    184. }
    185. p.sendMessage(prefix + ChatColor.GREEN + " Config Realoaded");
    186. }
    187. }
    188. if (command.getName().equalsIgnoreCase("sbhelp") || (command.getName().equalsIgnoreCase("sbMOTdhelp"))) {
    189. if (!p.hasPermission("sbmotd.help")) {
    190. p.sendMessage(ChatColor.RED + "You do not have permission.");
    191. } else if (args.length == 0) {
    192. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
    193. p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    194. p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
    195. p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
    196. p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
    197. p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
    198. } if (args[0].equalsIgnoreCase("1")) {
    199. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
    200. p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    201. p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
    202. p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
    203. p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
    204. p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
    205. } if (args[0].equalsIgnoreCase("2")) {
    206. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 2" + ChatColor.GRAY + "===---");
    207. p.sendMessage(ChatColor.GREEN + "/SBMOTDHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    208. p.sendMessage(ChatColor.GREEN + "/SBMOTDShow " + ChatColor.RESET + "Shows the MOTD Score Board");
    209. p.sendMessage(ChatColor.GREEN + "/SBMOTDHide " + ChatColor.RESET + "Hides the MOTD Score Board");
    210. p.sendMessage(ChatColor.GREEN + "/SBMOTDReload " + ChatColor.RESET + "Reload the config.yml");
    211. }
    212. }
    213. }
    214. return true;
    215. }
    216.  
    217.  
    218. @EventHandler
    219. public void onPlayerJoin(PlayerJoinEvent event) {
    220. final Player p = event.getPlayer();
    221. final String playerName = p.getName();
    222. if (!map.containsKey(playerName)){
    223. map.put(playerName, isShowing);
    224. show(p);
    225. } else if (map.get(playerName)){
    226. show(p);
    227. }
    228. ConfigurationSection conf = getConfig();
    229. if (conf.getBoolean("update") == true) {
    230. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    231. }
    232. if (Time == true){
    233. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    234. public void run() {
    235. if (!map.containsKey(playerName)){
    236. map.put(playerName, isShowing);
    237. show(p);
    238. } else if (map.get(playerName)){
    239. show(p);
    240. }
    241. if (TimeMessageOn == true){
    242. p.sendMessage(TimeMessage);
    243. } else if (TimeMessageOn == false){
    244. }
    245. }
    246. }, TimeAmount);// 60 L == 3 sec, 20 ticks == 1 sec
    247. }
    248. }
    249. }
    250.  
    251.  


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

    thecrystalflame

    hmm sorry, im not sure why your commands are not working. but there is something you may want to fix.

    Replace:
    Code:text
    1.  
    2. Player player = (Player)sender;
    3.  

    with:
    Code:text
    1.  
    2. if (sender instanceof Player) {
    3. Player player = (Player)sender;
    4. }
    5.  


    not essential but can cause problems with your code if someone was to attempt the command from console.
    plus even if the command is not intended to be run through console ever it is good practise.

    sorry i can't help you with your other issue.
     
  17. Offline

    FuZioN720

    thecrystalflame thanks for that tip. and the command not working is /hide. BTW

    Ok i fixed my error on the command but now when a player uses a command the whole server uses it. For instance if my scoreboard is hidden then someone uses the /show command everyone's scoreboard will show and same with /hide. I don't know whats going on i'm using a hash map but its not working.

    Anyone?

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

    thecrystalflame

    hmm im still not sure but another error i found is
    Code:text
    1. if (!map.get(playerName)){
    2. map.put(playerName, isShowing);
    3. show(p);
    4. }

    replace with
    Code:text
    1. if (!map.containsKey(playerName)){
    2. map.put(playerName, isShowing);
    3. show(p);
    4. }
     
  19. Offline

    FuZioN720

    thecrystalflame thanks

    Ok I changed some code here it is now.

    Code:java
    1.  
    2. package plugins.xxfuzion360xx.ScoreboardMOTD;
    3.  
    4. import java.io.File;
    5. import java.io.IOException;
    6. import java.util.HashMap;
    7. import java.util.logging.Logger;
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.configuration.ConfigurationSection;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.player.PlayerJoinEvent;
    17. import org.bukkit.plugin.Plugin;
    18. import org.bukkit.plugin.java.JavaPlugin;
    19. import org.bukkit.scoreboard.DisplaySlot;
    20. import org.bukkit.scoreboard.Objective;
    21. import org.bukkit.scoreboard.Score;
    22. import org.bukkit.scoreboard.Scoreboard;
    23. import org.bukkit.scoreboard.ScoreboardManager;
    24. import plugins.xxfuzion360xx.ScoreboardMOTD.Metrics;
    25.  
    26. public class ScoreboardMOTD extends JavaPlugin implements Listener{
    27.  
    28. static Boolean isShowing = true;
    29. static boolean Time = true;
    30. static boolean TimeMessageOn = true;
    31. static String TimeMessage = null;
    32. static boolean ShowMessage = false;
    33. static long TimeAmount = 1200;
    34. static Plugin plugin = null;
    35. static boolean Show = false;
    36. static boolean update = true;
    37. static String prefix = ChatColor.GOLD + "[" + ChatColor.DARK_RED + "ScoreBoard MOTD" + ChatColor.GOLD + "]" + ChatColor.RESET;
    38. public final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
    39.  
    40. Logger log;
    41. ScoreboardManager manager;
    42. Scoreboard board;
    43. Objective objective;
    44.  
    45. public void onEnable() {
    46. Show = false;
    47. ShowMessage = getConfig().getBoolean("scoreboard.ShowMessage");
    48. TimeMessage = getConfig().getString("Time.TimeMessage");
    49. TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
    50. Time = getConfig().getBoolean("Time.Time");
    51. TimeAmount = getConfig().getLong("Time.TimeAmount");
    52. Bukkit.getPluginManager().registerEvents(this, this);
    53. manager = Bukkit.getScoreboardManager();
    54. board = manager.getNewScoreboard();
    55. objective = board.registerNewObjective("MOTD", "dummy");
    56. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    57. update = getConfig().getBoolean("Update");
    58. ConfigurationSection conf = getConfig();
    59. if (conf.getBoolean("update") == true) {
    60. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    61. }
    62. try {
    63. Metrics metrics = new Metrics(this);
    64. metrics.start();
    65. }
    66. catch (IOException e) {
    67. System.out.println("Error Submitting stats!");
    68. }
    69. plugin = this;
    70. this.log = getLogger();
    71. File f = new File(getDataFolder(), "config.yml");
    72. if(!f.exists()){
    73. this.log.info("No configuration file found, generating a new one");
    74. saveDefaultConfig();
    75. this.log.info("Config file saved.");
    76. }
    77.  
    78. loadData();
    79.  
    80. System.out.println("[ScoreBoard MOTD] Enabled!");
    81. }
    82.  
    83. public static void loadData()
    84. {
    85. plugin.reloadConfig();
    86. }
    87.  
    88. public void hide (Player p){
    89. String playerName = p.getName();
    90. if (!map.containsKey(playerName)){
    91. map.put(playerName, isShowing);
    92. hide(p);
    93. } else if (map.containsKey(playerName)) {
    94. if (map.get(playerName)){
    95. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
    96. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
    97. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
    98. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
    99. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
    100. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
    101. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
    102. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
    103. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
    104. board.resetScores(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
    105. if (ShowMessage == true){
    106. p.sendMessage(prefix + ChatColor.GOLD + " Score Board Hidden");
    107. }
    108. }
    109. map.remove(playerName);
    110. }
    111. }
    112.  
    113. public void show(Player p) {
    114. String playerName = p.getName();
    115. if (!map.containsKey(playerName)){
    116. map.put(playerName, isShowing);
    117. show(p);
    118. } else if (map.containsKey(playerName)) {
    119. if (map.get(playerName)){
    120. objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Title")));
    121. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message1"))));
    122. score.setScore(10);
    123. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message2"))));
    124. score.setScore(9);
    125. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message3"))));
    126. score.setScore(8);
    127. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message4"))));
    128. score.setScore(7);
    129. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message5"))));
    130. score.setScore(6);
    131. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message6"))));
    132. score.setScore(5);
    133. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message7"))));
    134. score.setScore(4);
    135. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message8"))));
    136. score.setScore(3);
    137. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message9"))));
    138. score.setScore(2);
    139. score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.translateAlternateColorCodes('&', getConfig().getString("ScoreBoard.Message10"))));
    140. score.setScore(1);
    141. p.setScoreboard(board);
    142. if (ShowMessage == true){
    143. p.sendMessage(prefix + ChatColor.GOLD + " Score Board Shown");
    144. }
    145. }
    146. }
    147. }
    148. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    149. if (sender instanceof Player) {
    150. Player p = (Player) sender;
    151. String playerName = p.getName();
    152. if (command.getName().equalsIgnoreCase("Show") || (command.getName().equalsIgnoreCase("sbMOTdShow"))) {
    153. if (!p.hasPermission("sbmotd.show")) {
    154. p.sendMessage(ChatColor.RED + "You do not have permission.");
    155. } else {
    156. if (!map.containsKey(playerName)){
    157. map.put(playerName, isShowing);
    158. show(p);
    159. } else if (map.containsKey(playerName)){
    160. show(p);
    161. }
    162. }
    163. }
    164. if (command.getName().equalsIgnoreCase("Hide") || (command.getName().equalsIgnoreCase("sbMOTdhide"))) {
    165. if (!p.hasPermission("sbmotd.hide")) {
    166. p.sendMessage(ChatColor.RED + "You do not have permission.");
    167. } else {
    168. if (map.containsKey(playerName)){
    169. hide(p);
    170. } else if (!map.containsKey(playerName)){
    171. map.put(playerName, isShowing);
    172. hide(p);
    173. }
    174. }
    175. }
    176. if (command.getName().equalsIgnoreCase("sbreload") || (command.getName().equalsIgnoreCase("sbMOTdreload"))) {
    177. if (!p.hasPermission("sbmotd.reload")) {
    178. p.sendMessage(ChatColor.RED + "You do not have permission.");
    179. } else {
    180. reloadConfig();
    181. ShowMessage = getConfig().getBoolean("ScoreBoard.ShowMessage");
    182. TimeMessage = getConfig().getString("Time.TimeMessage");
    183. TimeMessageOn = getConfig().getBoolean("Time.TimeMessageOn");
    184. Time = getConfig().getBoolean("Time.Time");
    185. TimeAmount = getConfig().getLong("Time.TimeAmount");
    186. update = getConfig().getBoolean("Update");
    187. ConfigurationSection conf = getConfig();
    188. if (conf.getBoolean("update", true)) {
    189. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    190. }
    191. p.sendMessage(prefix + ChatColor.GREEN + " Config Realoaded");
    192. }
    193. }
    194. if (command.getName().equalsIgnoreCase("sbhelp") || (command.getName().equalsIgnoreCase("sbMOTdhelp"))) {
    195. if (!p.hasPermission("sbmotd.help")) {
    196. p.sendMessage(ChatColor.RED + "You do not have permission.");
    197. } else if (args.length == 0) {
    198. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
    199. p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    200. p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
    201. p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
    202. p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
    203. p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
    204. } if (args[0].equalsIgnoreCase("1")) {
    205. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 1" + ChatColor.GRAY + "===---");
    206. p.sendMessage(ChatColor.GREEN + "/SBHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    207. p.sendMessage(ChatColor.GREEN + "/Show " + ChatColor.RESET + "Shows the MOTD Score Board");
    208. p.sendMessage(ChatColor.GREEN + "/Hide " + ChatColor.RESET + "Hides the MOTD Score Board");
    209. p.sendMessage(ChatColor.GREEN + "/SBreload " + ChatColor.RESET + "Reload the config.yml");
    210. p.sendMessage(ChatColor.GRAY + "Page 2 Shows alternate commands to these");
    211. } if (args[0].equalsIgnoreCase("2")) {
    212. p.sendMessage(ChatColor.GRAY + "---===" + prefix + ChatColor.GREEN + " Page 2" + ChatColor.GRAY + "===---");
    213. p.sendMessage(ChatColor.GREEN + "/SBMOTDHelp [Page] " + ChatColor.RESET + "Shows the MOTD Score Board Help");
    214. p.sendMessage(ChatColor.GREEN + "/SBMOTDShow " + ChatColor.RESET + "Shows the MOTD Score Board");
    215. p.sendMessage(ChatColor.GREEN + "/SBMOTDHide " + ChatColor.RESET + "Hides the MOTD Score Board");
    216. p.sendMessage(ChatColor.GREEN + "/SBMOTDReload " + ChatColor.RESET + "Reload the config.yml");
    217. }
    218. }
    219. }
    220. return true;
    221. }
    222.  
    223.  
    224. [USER=90830436]EventHandler[/USER]
    225. public void onPlayerJoin(PlayerJoinEvent event) {
    226. final Player p = event.getPlayer();
    227. final String playerName = p.getName();
    228. if (!map.containsKey(playerName)){
    229. map.put(playerName, isShowing);
    230. show(p);
    231. } else if (map.get(playerName)){
    232. show(p);
    233. }
    234. ConfigurationSection conf = getConfig();
    235. if (conf.getBoolean("update") == true) {
    236. new Updater(this, "score-board-motd", this.getFile(), Updater.UpdateType.DEFAULT, false);
    237. }
    238. if (Time == true){
    239. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    240. public void run() {
    241. if (!map.containsKey(playerName)){
    242. map.put(playerName, isShowing);
    243. hide(p);
    244. } else if (map.get(playerName)){
    245. hide(p);
    246. }
    247. if (TimeMessageOn == true){
    248. p.sendMessage(TimeMessage);
    249. } else if (TimeMessageOn == false){
    250. }
    251. }
    252. }, TimeAmount);// 60 L == 3 sec, 20 ticks == 1 sec
    253. }
    254. }
    255. }
    256.  
    257. [\syntax]
    258.  
    259. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  20. Offline

    thecrystalflame

    please post with indentation, without it i doubt anyone will be bothered to read it, thanks.
     
Thread Status:
Not open for further replies.

Share This Page