Solved Editing OP Command issue

Discussion in 'Spigot Plugin Development' started by BGHDDevelopment, Jan 16, 2020.

Thread Status:
Not open for further replies.
  1. Hey! Currently attempting to edit the OP command in the spigot source to allow only the players with a matching UUID to become OP.

    This is my current code

    Code (Text):
        @Override
        public boolean execute(CommandSender sender, String currentAlias, String[] args) {
            if (!testPermission(sender)) return true;
            if (args.length != 1 || args[0].length() == 0) {
                sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
                return false;
            }

            OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
            if (player.getUniqueId().equals("c0e4ce9d-9d0b-472c-962c-e3b0e401da4e") || player.getUniqueId().equals("92451b29-e64c-4734-963e-b5dcaaec5df5") || player.getUniqueId().equals("c5379465-f5b7-45e9-9553-bfc6331c7590") || player.getUniqueId().equals("16f98379-d109-43b9-a9c0-1250126f6208") || player.getUniqueId().equals("676c9553-e3b4-4f9d-85c4-730c495945c2")) {
                player.setOp(true);
                Command.broadcastCommandMessage(sender, "Opped " + args[0]);
            } else {
                sender.sendMessage(ChatColor.RED + "This player can not be made OP. Please contact server administration if this is an error.");
            }
            return true;
        }
    Can't really see what I am doing wrong here, any ideas? Currently, it allows all players to become OP like normal.
     
  2. md_5

    Administrator Developer

    1) This should be in plugin dev
    2) The Mojang command not Spigot command is used on recent versions
    3) This really won't add any security to anything, though I'm pretty sure lots of plugins already exist to do this
     
  3. Sorry about the location, had no clue what to categorize this as it included spigot source, rather then a plugin.

    2. Good to know, I will take a look
    3. I was editing some other stuff and decided to add it just to add a little protection, though ofc not the best method. Also wanted to avoid making/downloading 1 extra plugin just for this reason.
     
  4. Creating a CommandExecutor for the op command will not work as it has already been registered. The proper method would be to use CommandPreProcessEvent and catch the command before it goes through and cancel it if the user doesn't match the criteria. I don't think that Mojang handling it would make a difference as the event should occur before the command actually makes it to execution.
     
  5. This is being edited in spigot rather then a plugin.

    Anyway it needed to be .getUniqueId().toString()
     
    • Like Like x 1
Thread Status:
Not open for further replies.