No perms msg override

Discussion in 'Plugin Development' started by RoxioCZ, Feb 10, 2019.

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

    RoxioCZ

    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 main class:
    Code:
    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:
    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.
     
  2. Offline

    timtower Ninja on the waves Moderator

    @RoxioCZ If this is the only plugin installed, do you still get the message?
     
  3. Offline

    RoxioCZ

  4. Offline

    timtower Ninja on the waves Moderator

    Then what is adding /healme besides your plugin? Because it isn't a vanilla command.
     
  5. Offline

    RoxioCZ

    I know it isn't a vanilla command. I don't get the question, nothing is adding it cause I have no more plugins installed besides PEX to work with perms for now.
     
  6. Offline

    timtower Ninja on the waves Moderator

  7. Offline

    RoxioCZ

    Attached Files:

  8. Offline

    timtower Ninja on the waves Moderator

    Locked
    Offline mode is not supported by Bukkit
     
Thread Status:
Not open for further replies.

Share This Page