Solved Why not consider what I wrote?

Discussion in 'Plugin Development' started by ToldiIII, Mar 25, 2017.

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

    ToldiIII

    Code:
    package eu.montlikadani.TeleportSigns;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
       FileConfiguration config = getConfig();
    
       @Override
      public void onEnable() {
         saveDefaultConfig();
      config = getConfig();
    
         getConfig().options().copyDefaults(true);
      this.saveConfig();
      this.loadConfig();
      }
      public void loadConfig() {
    
      }
      @Override
       public void onDisable() {
         saveDefaultConfig();
       }
       @Override
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
         if (cmd.getName().equalsIgnoreCase("tsreload")) {
           if (!sender.hasPermission("teleportsigns.reload")) {
           }
           if (args.length > 0) {
             sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("unknowncommand")));
             return false;
           }
         } else {
           sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("nopermission"))); <-- That would be a problem in that it does not take into account and instead writes else, not what you have given. I have been put everywhere, even over my head, but not great. (This text is not included!)
         }
               reloadConfig();
               saveConfig();
               sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("pluginreload")));
               return true;
       }
    }
    
    Plugin.yml:
    Open! (open)

    name: TeleportSigns
    main: eu.montlikadani.TeleportSigns.Main
    version: 1.3.3
    author: montlikadani

    commands:
    tsreload:
    description: Config.yml file reload.
    aliases: [tsr]
    permission: teleportsigns.reload
    permissions:
    teleportsigns.*:
    default: op
    children:
    teleportsigns.reload: true
    teleportsigns.reload:
    default: op


    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (cmd.getName().equalsIgnoreCase("tsreload")) {
    if (!sender.hasPermission("teleportsigns.reload")) {
    }
    if (args.length > 0) {
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("unknowncommand")));
    return false;
    }
    } else {
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("nopermission"))); <-- That would be a problem in that it does not take into account and instead writes else, not what you have given. I have been put everywhere, even over my head, but not great. (This text is not included!)
    }
    reloadConfig();
    saveConfig();
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("pluginreload")));
    return true;
    }

    This right is not detected for some reason. Where do or what to do?
     
    Last edited: Apr 1, 2017
  2. Offline

    Zombie_Striker

    Don't log your own plugins. Bukkit does this for you. Remove these lines.

    Don't use command label. Instead, use cmd.getName()
    Main problem:Do you see that comma? It is not supposed to be there. Instead, there should be a close parentheses there. Not only that, but the rest of the string looks like what nopermission is supposed to be.
     
  3. Offline

    ToldiIII

    All right. Somehow he thought so?:

    Code:
    package eu.montlikadani.TeleportSigns;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class Main extends JavaPlugin implements Listener {
       FileConfiguration config = getConfig();
    
      public void onEnable() {
         saveDefaultConfig();
      config = getConfig();
         
         getConfig().options().copyDefaults(true);
      this.saveConfig();
      this.loadConfig();
      }
      public void loadConfig() {
         
      }
       
       public void onDisable() {
         saveDefaultConfig();
       }
       
       @Override
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
         if(sender.hasPermission("teleportsigns.reload") && (cmd.getName().equalsIgnoreCase("tsreload")) && sender.isOp()) {
               if (args.length > 0) {
                 sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("unknowncommand")));
                 return false;
               }
               reloadConfig();
               saveConfig();
               sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("pluginreload")));
         } else {
           sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("nopermission"))); <-- This somehow does not take into
    account.
             return true;
         }
         return true;
       }
    }
    
     
    Last edited: Mar 29, 2017
  4. Offline

    Zombie_Striker

    Remove the bold (including the comma).
     
  5. Offline

    ToldiIII

    Okay, and then what to write or what to delete?
     
  6. Offline

    mehboss

    @ToldiIII
    You are making "..RED + You don't have perm...." part of the config string you are getting, you forgot to add a parenthesis.
     
  7. Offline

    ToldiIII

    @mehboss. I did not leave out brackets. The brace is in the end is the end of three brackets.
     
  8. Offline

    Drkmaster83

    @Zombie_Striker @mehboss The part after the comma is meant to be there.

    What precisely is the problem? Any errors in the console? It could be that your config is null entirely for all we know. Also - You're using the net.md_5 ChatColor import... you should use Bukkit's since you aren't using a Bungee server. This could even be the problem.
     
    Last edited: Mar 26, 2017
    mehboss and Zombie_Striker like this.
  9. Offline

    mehboss

  10. Offline

    Zombie_Striker

    @mehboss
    Basically, this lets us achieve the following with one parameter:
    Code:
    if(config.contains(path)&&config.get(path) instanceof String){
      ......getString(path);
    }else{
     //Config does not have a correct path, sending a default message
     ...."Another message that can be sent"
    }
     
  11. Offline

    ToldiIII

    @Drkmaster83
    The "net.md_5.bungee.api.ChatColor;" there is no problem importing. But it would be permission not to recognize the right of what I've added.
     
  12. Offline

    Drkmaster83

    Please repost your plugin.yml in code brackets, or edit your first post and modify the code/plugin.yml and put them in code blocks.
    I know that the ChatColor import works, but you really should use Bukkit's import instead. And what the problem is-- sorry, it's terribly difficult to understand you -- is that you always have no permission, or that you always have permission?
     
  13. Offline

    ToldiIII

    I mean, if you type the command in the default player can not enter the text length to him but another text, which is specified in the config.yml file.
     
  14. Offline

    ToldiIII

    We continue to wait for the answers!
     
  15. Offline

    timtower Administrator Administrator Moderator

  16. Offline

    ToldiIII

    @timtower No. That would be the problem that ignores this text:
    Code:
            } else {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("nopermission")));
    
     
    Last edited: Apr 1, 2017
  17. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII Please post your updated code and config.
     
  18. Offline

    ToldiIII

    Code:
    PHP:
    package eu.montlikadani.TeleportSigns;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;

    public class 
    Main extends JavaPlugin {
        
    FileConfiguration config getConfig();

        @
    Override
        
    public void onEnable() {
            
    saveDefaultConfig();
            
    config getConfig();
         
            
    getConfig().options().copyDefaults(true);
            
    this.saveConfig();
            
    this.loadConfig();
        }
        public 
    void loadConfig() {
         
        }
     
        @
    Override
        
    public void onDisable() {
            
    saveDefaultConfig();
        }

        @
    Override
        
    public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args) {
            if (
    cmd.getName().equalsIgnoreCase("tsreload")) {
                if (!
    sender.hasPermission("teleportsigns.reload")) {
                }
                if (
    args.length 0) {
                    
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&'getConfig().getString("unknowncommand")));
                    return 
    false;
                }
            } else {
                
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&'getConfig().getString("nopermission")));
            }
                        
    reloadConfig();
                        
    saveConfig();
                        
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&'getConfig().getString("pluginreload")));
                        return 
    true;
        }
    }
    Config.yml:
    Code:
    # -----------------------------------------------
    # Welcome to the config.yml of TeleportSigns!
    # -----------------------------------------------
    # config.yml file. This file is edited you can feel, just do not rewrite the words before the colon, because if we rewrite the plugin will not work properly!
    # Message when a player tries to connect to offline server.
    #
    # [Tips]
    # - Use color coding '&' character, on this page:
    # http://minecraft.gamepedia.com/Formatting_codes
    # ------------------------------------------------
    # Messages. Default language: 'EN' English.
    # Feel free to edit this text except for times not to begin before the colon before the text, because if you delete or transfer will not work with the plugin.
    pluginreload: '&aThe plugin successfully reloaded!'
    nopermission: '&cYou don''t have permission for that!'
    unknowncommand: '&cUnknown command.'
    playeronly: '&cSorry but that can only be run by a player!'
    
     
    Last edited by a moderator: Apr 1, 2017
  19. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII Your code blocks are weird.
    Your permission check is closed right away.
    The else statement is for the cmd.getName
     
  20. Offline

    ToldiIII

    @timtower All right, I mean, what can I do about it?
     
  21. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII Hit ctrl+shift+f, should make things clear
     
  22. Offline

    ToldiIII

  23. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII No, then the indentation gets fixed and you can move things around.
     
  24. Offline

    ToldiIII

    Okay thank you!

    @timtower Oh, and you do not need to delete or something like that somewhere?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  25. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII Nothing needs to be deleted, all code that you need is in there, just need to move it around.
     
  26. Offline

    ToldiIII

    @timtower Yes, and I put this to:

    HTML:
            } else {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("nopermission")));
            }
    
    Below this?:
    PHP:
        public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args) {
            if (
    cmd.getName().equalsIgnoreCase("tsreload")) {
                if (!
    sender.hasPermission("teleportsigns.reload")) {
     
  27. Offline

    timtower Administrator Administrator Moderator

  28. Offline

    ToldiIII

    @timtower This is the last question! Only this text should be subject?:
    PHP:
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&'getConfig().getString("nopermission")));
     
  29. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII And the reloading itself should happen when you run the command with the correct permissions.
    Not always
     
  30. Offline

    ToldiIII

    @timtower Anyway, I checked off, and now is not good. I still write this: "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators hurt if you believe this is in error." Something else is wrong.
     
Thread Status:
Not open for further replies.

Share This Page