Op Protector

Discussion in 'Plugin Development' started by ShayBox, Aug 3, 2014.

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

    ShayBox

    I am currently working on a plugin, it has been created many times. but none of them are updated. basicly, it will override the /op command and requires a password for the /op or /deop to work. the password can be set in the config.yml. currently it auto-gens the folder and the config. but i need to find out a way to make it work /op <player> <pass> i dont understand args or configs yet. please help
    Main:
    Code:java
    1. package Manager;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.PluginDescriptionFile;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin{
    12. public static Main plugin;
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14.  
    15. public void onDisable() {
    16. PluginDescriptionFile p = this.getDescription();
    17. this.logger.info(p.getName() + " V" + p.getVersion() + "has been disabled");
    18. }
    19.  
    20. public void onEnable() {
    21. PluginDescriptionFile p = this.getDescription();
    22. this.logger.info(p.getName() + " V" + p.getVersion() + "has been enabled");
    23. getConfig().options().copyDefaults(true);
    24. saveConfig();
    25. }
    26.  
    27. public boolean onCommand(CommandSender sender, Command dms, String commandLabel, String[] args) {
    28. Player player = (Player)sender;
    29. if(commandLabel.equalsIgnoreCase("Op")) {
    30. if(player.hasPermission("bradkillsu.op")) {
    31. if(getConfig().getString("Password") != null){
    32. player.setOp(true);
    33. player.sendMessage("Hey You were Opped :D");
    34. }
    35. }
    36. }
    37. return false;
    38. }
    39. }

    Config.yml:
    Code:
    #Enter Passcode on line below
    Password: example123
    #Thanks for using Brad's Op Password Plugin!
    Plugin.yml:
    Code:
    name: Op-Secret
    version: 1.0.0
    author: BRAD
    description: Op command
     
    main: Manager.Main
     
    commands:
        Op:
            description: Secret Op
            usage: /Op
           
    permissions:
      bradkillsu.*:
        children:
          bradkillsu.op: true        
     
  2. Offline

    _Filip

    There isn't anything to understand about args... It's an array of strings...
     
  3. Offline

    Gater12

  4. Offline

    ShayBox

  5. Offline

    SmooshCakez


    Unless you use a PlayerCommandPreprocessEvent, I'm pretty sure Bukkit automatically takes priority over commands like /op. What you could do is make a CommandExecutor with your command, and then set the executor with a PlayerCommandPreprocessEvent. Example:

    Code:java
    1.  
    2. @EventHandler
    3. public void commandExecutor(PlayerCommandPreprocessEvent event) {
    4. if (event.getMessage().startsWith("/op")) { // So, if a player does /op...
    5. Bukkit.getServer().getPluginCommand("op").setExecutor(Your Command Executor);
    6. }
    7. }
    8.  


    If you're new enough to Bukkit not to know what a CommandExecutor is, just create another file, "Test.java" for example, then replace "Your Command Executor" with
    Code:
    new Test()
    Also, remember to put
    Code:
    implements CommandExecutor
    in the CommandExecutor if you're going to use this method. Then, just add the onCommand and everything to that file.
     
  6. Offline

    Gater12

    SmooshCakez
    No you can override some of the base commands from bukkit.
     
  7. Offline

    Infuzion

  8. Offline

    SmooshCakez

    A command executor would still be useful.
     
  9. Offline

    ShayBox

    1. READ ME CODE i have all that in there. 2. why cant anyone in the world be a developer and just fix it, i dont know 1 line, i need to import Password: form the config into a arg. just fix it and commend the new fixed code
     
  10. Offline

    SmooshCakez

    If you don't understand configuration files yet, you should take a look at Bukkit's configuration reference.
     
  11. Offline

    ShayBox

    Just a tip: you guys need to read. i dont want to learn it. i just want someone to fix line 31!!!!!!!!!! i dont care to learn java r anything else.
     
  12. Offline

    ulsa

    ShayBox we are here to assist and help :) no spoonfeeding
     
  13. Offline

    xTigerRebornx

    ShayBox If you don't want to learn Java and make the plugin yourself, then perhaps a Plugin Request would suit you better. This is a section for help, not for us to write code for you.
     
  14. Offline

    ShayBox

    ive seen all the links youv posted, and the tripple posts. none have anything todo with like 31 idk what to type on there, i just combined 2 types of code and put Password: but fine, if you guys are not true coders ill go get someone that will fix it

    (Pretend Locked)

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

    xTrollxDudex

    So you came here for someone to write code for you?
     
Thread Status:
Not open for further replies.

Share This Page