No perms message override

Discussion in 'Spigot Plugin Help' started by RoxioCZ, Feb 9, 2019.

  1. Hi,
    how can I force my plugin to display MY no perms message instead of the default one(I'm sorry, but you do not have permission to perform this command. Please contact the server admin...)

    My MainClass:
    Code (Java):

    package main;

    import org.bukkit.ChatColor;
    import org.bukkit.plugin.java.JavaPlugin;

    import commands.FlyCommand;
    import commands.GameModes;
    import commands.HealCommands;
    import commands.OverridedDefaultComannds;
    import commands.SpyingCommands;
    import events.JoinQuitEvent;

    public class Main extends JavaPlugin {

        public static String infoPrefix = ChatColor.translateAlternateColorCodes('&', "&4&lInfo&r >> ");
        public static String errorPrefix = ChatColor.translateAlternateColorCodes('&', "&4&lError&r >> ");
        public static String noPermsPrefix = ChatColor.translateAlternateColorCodes('&', "&4&lPerms&r >> ");

        public static String insufficientArgs = "Not enough arguments!";
        public static String playerNotOnline = "This player is not online right now!";
        public static String noPerms = noPermsPrefix + "You dont have permission to do that!";
        public static String unknownCmd = errorPrefix + "Unknown command!";
        public static String unknownCmdCon = "Unknown command!";

        @Override
        public void onEnable() {
            System.out.println("Plugin enabled!");
            this.getCommand("healme").setExecutor(new HealCommands());
            this.getCommand("heal").setExecutor(new HealCommands());
            this.getCommand("survival").setExecutor(new GameModes());
            this.getCommand("spectator").setExecutor(new GameModes());
            this.getCommand("creative").setExecutor(new GameModes());
            this.getCommand("adventure").setExecutor(new GameModes());
            this.getCommand("fly").setExecutor(new FlyCommand());
            this.getCommand("vanish").setExecutor(new SpyingCommands());
            this.getCommand("kill").setExecutor(new OverridedDefaultComannds());
            this.getCommand("seed").setExecutor(new OverridedDefaultComannds());
            this.getCommand("gamemode").setExecutor(new OverridedDefaultComannds());
            this.getCommand("teleport").setExecutor(new OverridedDefaultComannds());

            this.getServer().getPluginManager().registerEvents(new JoinQuitEvent(), this);

        }

        @Override
        public void onDisable() {
            System.out.println("Plugin disabled!");
        }
    }
    My other class:
    Code (Java):
    package commands;

    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 main.Main;

    public class HealCommands implements CommandExecutor {

        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("healme")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (player.hasPermission("command.healme")) {
                        if (((Player) sender).getHealth() >= 20) {
                            player.sendMessage(Main.errorPrefix + "You are already fully healed!");
                        } else {
                            player.setHealth(20);
                            player.setFoodLevel(20);
                            player.setFireTicks(0);
                            player.sendMessage(Main.infoPrefix + "You have been healed!");
                        }
                    } else {
                        player.sendMessage(Main.noPerms);
                    }
                } else {
                    sender.sendMessage("Only players can execute this command!");
                }
            }

            if (command.getName().equalsIgnoreCase("heal")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (player.hasPermission("command.heal")) {
                        if (args.length == 0) {
                            sender.sendMessage(Main.errorPrefix + "Please specify the player you want to heal!");
                        } else if (args.length == 1) {
                            Player target = Bukkit.getPlayer(args[0]);
                            if (target != null) {
                                if (target.getHealth() >= 20) {
                                    sender.sendMessage(Main.errorPrefix + "The player is already fully healed!");
                                } else {
                                    target.setHealth(20);
                                    target.sendMessage(Main.infoPrefix + "You have been healed by " + ChatColor.GOLD
                                            + player.getName() + "!");
                                    player.sendMessage(
                                            Main.infoPrefix + "You healed " + ChatColor.GOLD + target.getName() + "!");
                                }
                            } else {
                                sender.sendMessage(Main.errorPrefix + "This player is not on the server right now!");
                            }
                        } else if (args.length == 2) {
                            try {
                                Player target = Bukkit.getPlayer(args[0]);
                                if (target != null) {
                                    double currentHealth = target.getHealth();
                                    double addHealth = Double.parseDouble(args[1]);
                                    if ((currentHealth + addHealth) > 20) {
                                        target.setHealth(20);
                                        target.sendMessage(Main.infoPrefix + "You have been healed by " + ChatColor.GOLD
                                                + player.getName() + ChatColor.RESET + " for " + ChatColor.RED + addHealth
                                                + " health" + "!");
                                        player.sendMessage(Main.infoPrefix + "You healed " + ChatColor.GOLD
                                                + target.getName() + ChatColor.RESET + " for " + ChatColor.RED + addHealth
                                                + " health" + "!");
                                    } else {
                                        target.setHealth(currentHealth + addHealth);
                                        target.sendMessage(Main.infoPrefix + "You have been healed by " + ChatColor.GOLD
                                                + player.getName() + ChatColor.RESET + " for " + ChatColor.RED + addHealth
                                                + " health" + "!");
                                        player.sendMessage(Main.infoPrefix + "You healed " + ChatColor.GOLD
                                                + target.getName() + ChatColor.RESET + " for " + ChatColor.RED + addHealth
                                                + " health" + "!");
                                    }
                                } else {
                                    sender.sendMessage(Main.errorPrefix + "This player is not on the server right now!");
                                }
                            } catch (NumberFormatException event) {
                                sender.sendMessage(Main.errorPrefix + "Please use real numbers!");
                            }
                        }
                    } else {
                        player.sendMessage(Main.noPerms);
                    }
                } else {
                    if (args.length == 0) {
                        sender.sendMessage("Please specify the player you want to heal!");
                    } else if (args.length == 1) {
                        Player target = Bukkit.getPlayer(args[0]);
                        if (target != null) {
                            if (target.getHealth() >= 20) {
                                sender.sendMessage("The player is already fully healed!");
                            } else {
                                target.setHealth(20);
                                target.sendMessage(Main.infoPrefix + "You have been healed by " + ChatColor.GOLD
                                        + sender.getName() + "!");
                                sender.sendMessage(target.getName() + " have been healed!");
                            }
                        } else {
                            sender.sendMessage("This player is not on the server right now!");
                        }
                    } else if (args.length == 2) {
                        try {
                            Player target = Bukkit.getPlayer(args[0]);
                            if (target != null) {
                                double currentHealth = target.getHealth();
                                double addHealth = Double.parseDouble(args[1]);
                                if ((currentHealth + addHealth) > 20) {
                                    target.setHealth(20);
                                    target.sendMessage(
                                            Main.infoPrefix + "You have been healed by " + ChatColor.GOLD + sender.getName()
                                                    + ChatColor.RESET + " for " + ChatColor.RED + addHealth + " health!");
                                    sender.sendMessage(
                                            target.getName() + " have been healed for " + addHealth + " health!");
                                } else {
                                    target.setHealth(currentHealth + addHealth);
                                    target.sendMessage(
                                            Main.infoPrefix + "You have been healed by " + ChatColor.GOLD + sender.getName()
                                                    + ChatColor.RESET + " for " + ChatColor.RED + addHealth + " health!");
                                    sender.sendMessage(
                                            target.getName() + " have been healed for " + addHealth + " health!");
                                }
                            } else {
                                sender.sendMessage("This player is not on the server right now!");
                            }
                        } catch (NumberFormatException event) {
                            sender.sendMessage("Please use real numbers!");
                        }
                    }
                }
            }
            return true;
        }
    }
    I would be glad if I don't have to interfere with anything else than my plugin to fix this problem.

    Thanks for help, and sorry for maybe dumb question.
     

    Attached Files:

  2. I believe this is handled in the plugin.yml file. Check here: https://bukkit.gamepedia.com/Plugin_YAML.
    More specifically, the permission-message value.

    Note that I haven't tested this myself, but I'm 90% sure this is what you want.
     
    • Agree Agree x 1
  3. just remove the
    permissions:
    part in your plugin.yml the if(p.haspermissions) is handling your permissions no need to do this in the plugin.yml
     
    • Agree Agree x 1

Share This Page