Calling plugin.yml "permisson-message" when not wanted

Discussion in 'Plugin Development' started by ExtremeOrphan, Sep 11, 2019.

  1. Offline

    ExtremeOrphan

    For some reason my plugin is returning the "permission-message" message from the plugin.yml instead of the one in my code which SHOULD be called if they don't have the proper permission defined in WantedCommand.java . Trying to debug I set all the returns to true so that it shouldn't call the plugin.yml yet it continues to call on it for all else statements to "if (p.hasPermission("")) {" blocks.

    EDIT: Also probably worth noting that all the other else statements in my plugin call on the correct message from the config.yml

    Main.java
    Code:
    package com.jeremyrpeters.vcwantedlist;
    
    import java.util.HashSet;
    
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        FileConfiguration config = this.getConfig();
    
        public static HashSet<String> wanted_list = new HashSet<String>();
    
        @Override
        public void onEnable() {
    
            PluginManager pm = getServer().getPluginManager();
       
            pm.registerEvents(new EventListener(this), this);
       
            getCommand("wanted").setExecutor(new WantedCommand(this));
       
            generateConfig();
       
            config.options().copyDefaults(true);
       
            saveConfig();
       
        }
    
        @Override
        public void onDisable() {
       
        }
    
        public void generateConfig() {
       
            config.addDefault("Prefix", "&8[&2Wanted List&8] ");
            config.addDefault("Messages.Wanted List Added", "&aSuccessfully added %player% to the wanted list.");
            config.addDefault("Messages.Player Already Wanted", "&cError, %player% has already been declared as wanted!");
            config.addDefault("Messages.Wanted List Removed", "&aSuccessfully removed %player% to wanted list.");
            config.addDefault("Messages.Player Not Wanted", "&cError, %player% is not wanted!");
            config.addDefault("Messages.Wanted Player Left", "&c%player%, who was wanted has left the game.");
            config.addDefault("Messages.Cant Find Player", "&cIt appears that player isnt online!");
            config.addDefault("Messages.Plugin Reloaded", "&aPlugin config reloaded!");
            config.addDefault("Messages.No Permission", "&cError, you dont have permission for this!");
       
        }
    }
    
    WantedCommand.java
    Code:
    package com.jeremyrpeters.vcwantedlist;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import com.jeremyrpeters.vcwantedlist.Main;
    
    public class WantedCommand implements CommandExecutor {
    
        Main plugin;
     
        public WantedCommand (Main instance) {
       
            plugin = instance;
    
        }
    
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
       
            if(cmd.getName().equalsIgnoreCase("wanted")) {
           
                Player p = (Player) sender;
           
                if (args[0].equalsIgnoreCase("add")) {
               
                    if (p.hasPermission("vcwanted.use")) {
               
                        if (args.length == 2) {
               
                            Player target = Bukkit.getPlayerExact(args[1]);
                   
                            if (Bukkit.getOnlinePlayers().contains(target)) {
                   
                                if (!(Main.wanted_list.contains(target.getName()))) {
                   
                                    Main.wanted_list.add(target.getName());
                   
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Wanted List Added").replaceAll("%player%", target.getPlayer().getName())));
                                }
                           
                                else {
                               
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Player Already Wanted").replaceAll("%player%", target.getPlayer().getName())));
                                }
                            }
                       
                            else {
                           
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Cant Find Player")));
                       
                            }
                        }
                   
                        else {
                       
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.RED + "Error, please specify a player! e.g., /wanted add ExtremeOrphan");
                        }
                    }
               
                    else {
               
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.No Permission")));
                    }
               
                }
           
                if (args[0].equalsIgnoreCase("list")) {
               
                    if (!(Main.wanted_list.isEmpty())) {
                   
                        String wanted_list = Main.wanted_list.toString().replaceAll("[" , "").replaceAll("]", "");
                                           
                        p.sendMessage(ChatColor.DARK_GREEN + "Wanted List:");
                        p.sendMessage("");
                        p.sendMessage(ChatColor.GREEN + wanted_list);
               
                    }
               
                    else {
                   
                        p.sendMessage(ChatColor.DARK_GREEN + "Wanted List:");
                        p.sendMessage("");
                        p.sendMessage(ChatColor.GREEN + "No one is wanted at the moment!");
                   
                    }
                }
           
                if (args[0].equalsIgnoreCase("remove")) {
               
                    if (p.hasPermission("vcwanted.use")) {
    
                        if (args.length == 2) {
                   
                            Player target = Bukkit.getPlayerExact(args[1]);
                   
                            if (Bukkit.getOnlinePlayers().contains(target)) {
    
                                if (Main.wanted_list.contains(target.getName())) {
                               
                                    Main.wanted_list.remove(target.getName());
                   
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Wanted List Removed").replaceAll("%player%", target.getPlayer().getName())));
                       
                                }
                   
                                else {
                       
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Player Not Wanted").replaceAll("%player%", target.getPlayer().getName())));
                                }
                            }
                       
                            else {
                           
                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Cant Find Player").replaceAll("%player%", target.getPlayer().getName())));
                            }
                        }
               
                        else {
                   
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.RED + "Error, please specify a player! e.g., /wanted remove ExtremeOrphan");
                   
                        }
                    }
               
                    else {
               
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.No Permission")));
                    }
                }
           
                if (args[0].equalsIgnoreCase("reload")) {
               
                    if (p.hasPermission("vcwanted.reload")) {
                   
                        plugin.reloadConfig();
                   
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.Plugin Reloaded")));
    
                    }
               
                    else {
                   
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Messages.No Permission")));
    
                    }
                    return true;
                }
                return true;
            }
            return true;
        }
    }
    
     
    Last edited: Sep 11, 2019
  2. Online

    timtower Moderator Moderator

    @ExtremeOrphan I believe that it checks the plugin.yml before the code fires.
    Probably just want to remove the message and permission from the command in the yml
     
  3. Offline

    ExtremeOrphan

    @timtower I tried that and I started to get the default minecraft no permission message "I'm sorry but you do not have permission to perform this command. Please contact the server administrator if you believe that this is in error."
     
  4. Online

    timtower Moderator Moderator

    Did you also remove the permission?
     

Share This Page