Solved Import method requiring instance from another plugin

Discussion in 'Plugin Development' started by Maxpnl, Jun 2, 2017.

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

    Maxpnl

    Hello everyone, I basically need to use a method from another class to get a value inside it's config, this is what I tried so far but i'm getting an exception when I try to call the Main class (from the other plugin) to get his istance.

    package com.maxpnl.scoreboard;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    import com.maxpnl.classes.MoneyMan;
    import com.maxpnl.classes.Main;
    public class SBSys {
    private static final Main instance = new Main();
    public static boolean createScoreBoard(Player player){
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("scoreboard", "sb");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    int balance = new MoneyMan(instance).getFunds(player.getName());
    Score score = objective.getScore(ChatColor.YELLOW + "Golds:");
    score.setScore(balance);
    player.setScoreboard(board);
    return false;
    }
    }
     
  2. Offline

    Zombie_Striker

    @Maxpnl
    1. Don't create a new instance of the main class. Either pass its instance through this class's constructor, or use Bukkit.getPluginManager().getPlugin("PluginName").
    2. You do not own maxpnl.com. Do not use it in your package name. Either use a domain you own, your email adress, or use the format "me.<name..<project>"
     
  3. Offline

    Maxpnl

    What's the deal with using a domain you don't own in the package name?
     
  4. Offline

    Zombie_Striker

    @Maxpnl
    The package name specifies who the code belongs to. If you do not own the domain you are using, anyone using that domain can claim your code as their own (since you are using their domain). Just use a domain you own.
     
  5. Offline

    Jeyge

    @Zombie_Striker aren't you worried that someone might purchase zombiestriker.me at some point and own all of your code?
     
  6. Offline

    Maxpnl

    Btw, how do I convert the Plugin item to a Main item?

    private static final Plugin instance = Bukkit.getPluginManager().getPlugin("Levels");
    public static boolean createScoreBoard(Player player){
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("scoreboard", "sb");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    int balance = new MoneyMan(instance).getFunds(player.getName());
    Score score = objective.getScore(ChatColor.YELLOW + "Golds:");
    score.setScore(balance);
    player.setScoreboard(board);
    return false;

    It shows up this error "The constructor MoneyMan(Plugin) is undefined", and if I try to add a Main plugin = instance it says that you can't convert a Plugin type to a Main type, any clues?

    Here's the code I have inside the other class if you need it

    Main plugin;

    public MoneyMan(Main instance) {
    plugin = instance;
    }

    Sorry fixed this, now worries

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2017
Thread Status:
Not open for further replies.

Share This Page