Unspecified method

Discussion in 'Plugin Development' started by Ardno, Sep 24, 2019.

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

    Ardno

    Hello,

    I want to make Expansion for plugin PlaceholderAPI.
    Code:
    package me.ardno.placeholderapi.xgaming;
    
    import java.io.File;
    import org.bukkit.OfflinePlayer;
    import me.clip.placeholderapi.expansion.PlaceholderExpansion;
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    
    /**
    * This class will automatically register as a placeholder expansion
    * when a jar including this class is added to the directory
    * {@code /plugins/PlaceholderAPI/expansions} on your server.
    * <br>
    * <br>If you create such a class inside your own plugin, you have to
    * register it manually in your plugins {@code onEnable()} by using
    * {@code new YourExpansionClass().register();}
    */
    public class xgamingExpansion extends PlaceholderExpansion {
        private File playerFile;
    
        /**
         * This method should always return true unless we
         * have a dependency we need to make sure is on the server
         * for our placeholders to work!
         *
         * @return always true since we do not have any dependencies.
         */
        @Override
        public boolean canRegister(){
            return true;
        }
    
        /**
         * The name of the person who created this expansion should go here.
         *
         * @return The name of the author as a String.
         */
        @Override
        public String getAuthor(){
            return "ardno";
        }
    
        /**
         * The placeholder identifier should go here.
         * <br>This is what tells PlaceholderAPI to call our onRequest
         * method to obtain a value if a placeholder starts with our
         * identifier.
         * <br>This must be unique and can not contain % or _
         *
         * @return The identifier in {@code %<identifier>_<value>%} as String.
         */
        @Override
        public String getIdentifier(){
            return "xgaming";
        }
    
        /**
         * This is the version of this expansion.
         * <br>You don't have to use numbers, since it is set as a String.
         *
         * @return The version as a String.
         */
        @Override
        public String getVersion(){
            return "1.1";
        }
    
        /**
         * This is the method called when a placeholder with our identifier
         * is found and needs a value.
         * <br>We specify the value identifier in this method.
         * <br>Since version 2.9.1 can you use OfflinePlayers in your requests.
         *
         * @param  player
         *         A {@link org.bukkit.OfflinePlayer OfflinePlayer}.
         * @param  identifier
         *         A String containing the identifier/value.
         *
         * @return Possibly-null String of the requested identifier.
         */
     
        private double account;
        private String name;
     
        @Override
        public String onRequest(OfflinePlayer player, String identifier){
    
            // %xgaming_test1%
            if(identifier.equals("test")){
                return "placeholder1 works";
            }
    
            // %xgaming_test2%
            if(identifier.equals("test2")){
                return "placeholder2 works";
            }
         
            if(identifier.equals("web")) {
                return "www.xgaming.online";
            }
         
            if(identifier.equals("lop")) {
                int lop = 0;
             
                for (Player o : Bukkit.getOnlinePlayers()) {
                    if (o.getWorld().getName().equals(identifier)) {
                        lop = lop + 1;
            }
                }
             
                return String.valueOf(lop);
            }
         
            if(identifier.equals("money")) {
                YamlConfiguration config = YamlConfiguration.loadConfiguration(playerFile);
                new playerFile(System.getProperty("user.dir").getAbsolutePath() + "/plugins/Ultimate_Economy/PlayerFile.yml");
                this.account = config.getDouble(String.valueOf(name) + ".account amount");
                return String.valueOf(this.account);
            }
         
            return null;
        }
    }
    (There're 2 errors. In method .getAbsolutePath() and in new playerFile)

    It doesn't work :D
    Why?

    I'm working in Java first day :D
    And sorry for my english.

    - Ardno
     
    Last edited: Sep 24, 2019
  2. You should do some research on how object orientated programming works. I try to explain what you did wrong but I guess that isn't really helping you understand what you did wrong.
    The first line is basically correct you create a new YamlConfiguration Object and pass the playerFile Object. But this playerFile is null at the time you pass it. I guess you noticed that and you tried to initialize it in the next line but that is not quite how it works. playerFile is a variable created by you. To assign a value to it you need to create a new Object as you did it in the previous line. To do so, you type new ClassName(<arguments>) the class name in that case is File, not playerFile. You want to create a File, not a playerFile (there is no class named playerFile). To assign the new created Object to your variable use '='.

    Code:Java
    1. playerFile = new File(System.getProperty("user.dir") + "/plugins/Ultimate_Economy/PlayerFile.yml");
    2. YamlConfiguration config = YamlConfiguration.loadConfiguration(playerFile);

    As I said you'll probably just copy this but I highly recommend you to really understand it and therefor whatch tutorials or read a book about java if needed

    getAbsolutePath() throws an error because System#getProperty() returns a String which doesn't has a method called getAbsolutePath. It already returns the absolute path as a string as far as I know.

    Also if you need help again and have errors, please post them as well
     
  3. Offline

    Ardno

    upload_2019-9-24_21-5-0.png

    ok, thank, but how I get player name - which I'm showing scoreboard + which tutorials on yt you recommend?

    -Ardno
     
    Last edited: Sep 24, 2019
  4. This is a documentation which explains everything you can do with a class. There is one for almost every Class. I don't understand what you want to do, the playername? player.getName() again, do not use 'Player' but the name you gave the variable in your case 't'. Scoreboards? What do you want to do with the scoreboard?
    I dont really know good tutorials for the java basics since I tought it myself with books and learning by doing but I'm sure there are lots of videos in every language which you can use
     
  5. Offline

    Ardno

  6. Online

    timtower Administrator Administrator Moderator

    If you are using placeholder API then it should do that itself.
     
  7. Offline

    Ardno

    Yeah,

    but if somebody doesn't know, sends a post on this forum, how to complete code.
     
  8. Online

    timtower Administrator Administrator Moderator

    Then you should make a thread specific for the scoreboard, there is no proof anywhere that you are handling anything scoreboard related.
     
Thread Status:
Not open for further replies.

Share This Page