GUI

Discussion in 'Spigot Plugin Development' started by harveycat1, May 6, 2017.

  1. I need help getting my gui to work everything loads with no errors it also doesnt make the buildpath
    plus nothin happens when i type /missions i had a test message to test if it worked and it never did send a message so i dont think it is making it to the onCommand

    Code (Text):
    plugins/FactionMissions/Data/Players/" + u + ".yml
    Code (Text):
        public void onEnable() {
            Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "=======================================");
            Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "FactionMissions by harveycat1 was successfully Enabled");
            Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "=======================================");
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            this.config = getConfig();
            this.config.options().copyDefaults(true);
            saveConfig();
            listen();
            setupEconomy();
            this.cfile = new File(getDataFolder(), "config.yml");
            if (getServer().getPluginManager().isPluginEnabled("Vault")) {
                Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "=======================================");
                Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "Vault found. Hooking to it.");
                Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "=======================================");
            } else {
                Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "=======================================");
                Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Vault was not found.");
                Bukkit.getConsoleSender().sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "=======================================");
            }
        public void listen() {
            getServer().getPluginManager().registerEvents(new GUI(this), this);
            getServer().getPluginManager().registerEvents(new Events(this), this);
        }
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = (Economy) rsp.getProvider();
            return econ != null;
        }
        public static String color(String format)
        {
            return ChatColor.translateAlternateColorCodes('&', format);
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You must be a players!");
            }
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("missions")) {
                p.openInventory(GUI.homeGUI(p));
            }
            return true;
        }
    }
    Code (Text):
        public static Inventory homeGUI(Player p) {
            Inventory inv = Bukkit.createInventory(null, 9, color("&a&lFaction Missions"));
            PlayerData pcfg = new PlayerData(p.getUniqueId());
            double balance = Main.econ.getBalance(p);
            int kills = pcfg.getKill();
            int deaths = pcfg.getDeath();
            int missionscompleted = pcfg.getMissionsCompleted();

            ItemStack info = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
            SkullMeta infom = (SkullMeta) info.getItemMeta();
            List<String> infol = new ArrayList();
            infom.setDisplayName(color(plugin.getConfig().getString("&aInfo &8»")));
            infom.setOwner(p.getName());
            infol.add(color("&bPlayer missions completed: " + missionscompleted));
            infol.add(color("&cFaction methods completed: "));
            infol.add(color("&aBalance: " + balance));
            infom.setLore(infol);
            info.setItemMeta(infom);

            ItemStack spacer1 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer1m = spacer1.getItemMeta();
            spacer1m.setDisplayName(color(" "));
            spacer1.setItemMeta(spacer1m);

            ItemStack spacer2 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer2m = spacer2.getItemMeta();
            spacer2m.setDisplayName(color(" "));
            spacer2.setItemMeta(spacer2m);

            ItemStack spacer3 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer3m = spacer3.getItemMeta();
            spacer3m.setDisplayName(color(" "));
            spacer3.setItemMeta(spacer3m);

            ItemStack spacer4 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer4m = spacer4.getItemMeta();
            spacer4m.setDisplayName(color(" "));
            spacer4.setItemMeta(spacer4m);

            ItemStack topplayers = new ItemStack(Material.PAPER);
            ItemMeta topplayersm = topplayers.getItemMeta();
            List<String> topplayersl = new ArrayList();
            topplayersm.setDisplayName(color("&bTop Players"));
            topplayersl.add(color("&e1&8» "));
            topplayersl.add(color("&71&8» "));
            topplayersl.add(color("&61&8» "));
            topplayersl.add(color("&a1&8» "));
            topplayersl.add(color("&b1&8» "));
            topplayersm.setLore(topplayersl);
            topplayers.setItemMeta(topplayersm);

            ItemStack playermissions = new ItemStack(Material.BOOK);
            ItemMeta playermissionsm = playermissions.getItemMeta();
            List<String> playermissionsl = new ArrayList();
            playermissionsm.setDisplayName(color("&bPlayer Missions"));
            playermissionsl.add(color("&e1&8» "));
            playermissionsm.setLore(playermissionsl);
            playermissions.setItemMeta(playermissionsm);

            ItemStack topfactions = new ItemStack(Material.PAPER);
            ItemMeta topfactionsm = topplayers.getItemMeta();
            List<String> topfactionsl = new ArrayList();
            topfactionsm.setDisplayName(color("&bTop Factions"));
            topfactionsl.add(color("&e1&8» "));
            topfactionsl.add(color("&71&8» "));
            topfactionsl.add(color("&61&8» "));
            topfactionsl.add(color("&a1&8» "));
            topfactionsl.add(color("&b1&8» "));
            topfactionsm.setLore(topfactionsl);
            topfactions.setItemMeta(topfactionsm);

            ItemStack factionmissions = new ItemStack(Material.BOOK);
            ItemMeta factionmissionsm = topplayers.getItemMeta();
            List<String> factionmissionsl = new ArrayList();
            factionmissionsm.setDisplayName(color("&cFaction Missions"));
            factionmissionsl.add(color("&e1&8» "));
            factionmissionsm.setLore(factionmissionsl);
            factionmissions.setItemMeta(factionmissionsm);

            inv.setItem(0, spacer1);
            inv.setItem(1, playermissions);
            inv.setItem(2, topplayers);
            inv.setItem(3, spacer2);
            inv.setItem(4, info);
            inv.setItem(5, spacer3);
            inv.setItem(6, topfactions);
            inv.setItem(7, factionmissions);
            inv.setItem(8, spacer4);
            return inv;
        }
    }
     
    Code (Text):
        public static Inventory homeGUI(Player p) {
            Inventory inv = Bukkit.createInventory(null, 9, color("&a&lFaction Missions"));
            PlayerData pcfg = new PlayerData(p.getUniqueId());
            double balance = Main.econ.getBalance(p);
            int kills = pcfg.getKill();
            int deaths = pcfg.getDeath();
            int missionscompleted = pcfg.getMissionsCompleted();

            ItemStack info = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
            SkullMeta infom = (SkullMeta) info.getItemMeta();
            List<String> infol = new ArrayList();
            infom.setDisplayName(color(plugin.getConfig().getString("&aInfo &8»")));
            infom.setOwner(p.getName());
            infol.add(color("&bPlayer missions completed: " + missionscompleted));
            infol.add(color("&cFaction methods completed: "));
            infol.add(color("&aBalance: " + balance));
            infom.setLore(infol);
            info.setItemMeta(infom);

            ItemStack spacer1 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer1m = spacer1.getItemMeta();
            spacer1m.setDisplayName(color(" "));
            spacer1.setItemMeta(spacer1m);

            ItemStack spacer2 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer2m = spacer2.getItemMeta();
            spacer2m.setDisplayName(color(" "));
            spacer2.setItemMeta(spacer2m);

            ItemStack spacer3 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer3m = spacer3.getItemMeta();
            spacer3m.setDisplayName(color(" "));
            spacer3.setItemMeta(spacer3m);

            ItemStack spacer4 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
            ItemMeta spacer4m = spacer4.getItemMeta();
            spacer4m.setDisplayName(color(" "));
            spacer4.setItemMeta(spacer4m);

            ItemStack topplayers = new ItemStack(Material.PAPER);
            ItemMeta topplayersm = topplayers.getItemMeta();
            List<String> topplayersl = new ArrayList();
            topplayersm.setDisplayName(color("&bTop Players"));
            topplayersl.add(color("&e1&8» "));
            topplayersl.add(color("&71&8» "));
            topplayersl.add(color("&61&8» "));
            topplayersl.add(color("&a1&8» "));
            topplayersl.add(color("&b1&8» "));
            topplayersm.setLore(topplayersl);
            topplayers.setItemMeta(topplayersm);

            ItemStack playermissions = new ItemStack(Material.BOOK);
            ItemMeta playermissionsm = playermissions.getItemMeta();
            List<String> playermissionsl = new ArrayList();
            playermissionsm.setDisplayName(color("&bPlayer Missions"));
            playermissionsl.add(color("&e1&8» "));
            playermissionsm.setLore(playermissionsl);
            playermissions.setItemMeta(playermissionsm);

            ItemStack topfactions = new ItemStack(Material.PAPER);
            ItemMeta topfactionsm = topplayers.getItemMeta();
            List<String> topfactionsl = new ArrayList();
            topfactionsm.setDisplayName(color("&bTop Factions"));
            topfactionsl.add(color("&e1&8» "));
            topfactionsl.add(color("&71&8» "));
            topfactionsl.add(color("&61&8» "));
            topfactionsl.add(color("&a1&8» "));
            topfactionsl.add(color("&b1&8» "));
            topfactionsm.setLore(topfactionsl);
            topfactions.setItemMeta(topfactionsm);

            ItemStack factionmissions = new ItemStack(Material.BOOK);
            ItemMeta factionmissionsm = topplayers.getItemMeta();
            List<String> factionmissionsl = new ArrayList();
            factionmissionsm.setDisplayName(color("&cFaction Missions"));
            factionmissionsl.add(color("&e1&8» "));
            factionmissionsm.setLore(factionmissionsl);
            factionmissions.setItemMeta(factionmissionsm);

            inv.setItem(0, spacer1);
            inv.setItem(1, playermissions);
            inv.setItem(2, topplayers);
            inv.setItem(3, spacer2);
            inv.setItem(4, info);
            inv.setItem(5, spacer3);
            inv.setItem(6, topfactions);
            inv.setItem(7, factionmissions);
            inv.setItem(8, spacer4);
            return inv;
        }
    }
     
    Code (Text):
        public PlayerData(UUID u) {
            this.uuid = u;

            this.playerData = new File("plugins/FactionMissions/Data/Players/" + u + ".yml");
            this.playerDataCfg = YamlConfiguration.loadConfiguration(this.playerData);
        }

        public boolean checkExist() {
            return this.playerData.exists();
        }

        public void createUser() {
            if (!this.playerData.exists()) {
                try {
                    YamlConfiguration PlayerDataCfg = YamlConfiguration.loadConfiguration(this.playerData);

                    PlayerDataCfg.set("OnlineTime", Integer.valueOf(0));
                    PlayerDataCfg.set("Kill", Integer.valueOf(0));
                    PlayerDataCfg.set("Death", Integer.valueOf(0));
                    PlayerDataCfg.set("MissionsCompleted", Integer.valueOf(0));
                    playerDataCfg.save(this.playerData);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        public void createConfig() {
            try {
                this.playerData.createNewFile();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public FileConfiguration getStats() {
            return this.playerDataCfg;
        }

        public void saveStats() {
            try {
                getStats().save(this.playerData);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        public int getOnlineTime() {
            return this.playerDataCfg.getInt("OnlineTime");
        }
        public void setOnlineTime(int time) {
            this.playerDataCfg.set("OnlineTime", Integer.valueOf(getOnlineTime() + time));
        }
        public int getKill() {
            return this.playerDataCfg.getInt("Kill");
        }
        public void setKill() {
            this.playerDataCfg.set("Kill", Integer.valueOf(getKill() + 1));
        }
        public int getDeath() {
            return this.playerDataCfg.getInt("Death");
        }
        public void setDeath() {
            this.playerDataCfg.set("Death", Integer.valueOf(getDeath() + 1));
        }
        public int getMissionsCompleted() {
            return this.playerDataCfg.getInt("MissionsCompleted");
        }
        public void setMissionsCompleted() {
            this.playerDataCfg.set("MissionsCompleted", Integer.valueOf(getMissionsCompleted() + 1));
        }
    }
    Code (Text):
        @EventHandler
        public void onJoin(PlayerJoinEvent e)
        {
            UUID u = e.getPlayer().getUniqueId();
            PlayerData pcfg = new PlayerData(u);
            pcfg.createUser();
        }
    }
     
     
  2. Photon

    Supporter

  3. Are there any errors when you type in the command, and is the command recognized by the server and is a proper plugin.yml present? I also agree with @Photon, I doubt anyone will look through all your classes more than a skim, especially with no error.
     
  4. i know how to read stack trace there are no errors to read
     
  5. [​IMG]
    see no stack trace
     
  6. I think showing that this is true would have been more helpful: "everything loads with no errors"
    No idea why you didn't also include your plugin.yml too, seeing as you're having trouble with a command
    (unless you didn't make a plugin.yml...)

    You also cut off the top of the classes... Like, why?
     
    #6 iPyronic, May 6, 2017
    Last edited: May 6, 2017
  7. He dis make a plugin.yml else the server will throw an error that it wouldn't find the plugin.yml. However.
    The most likely solution is, do getCommand("missions").setExecutor(this, this); this will most likely work for you!
     
  8. ok thanks i will try that
     
  9. Test this modification I can not remember for sure but if I'm not mistaken it must be in String for Bukkit to get the file.

    Code (Text):
    public PlayerData(UUID u) {
            this.uuid = u;

            this.playerData = new File("plugins/FactionMissions/Data/Players/" + u.toString() + ".yml");
            this.playerDataCfg = YamlConfiguration.loadConfiguration(this.playerData);
        }
     
    • Agree Agree x 1
  10. In this case, the UUID would automatically be converted to a String by the compiler.
     
  11. Ah, it's kind of new yet in Java.

    Register the command in the main getCommand ("your command"). SetExecutator (this, this);
    And check if in plugin.yml if the command is registered correctly.
     
    • Like Like x 1