Solved How to update gui every restart/reload

Discussion in 'Spigot Plugin Development' started by GoNelson, Apr 24, 2017.

  1. Hello everyone!

    I just started making a new plugin today, called BugReportPlus.
    So bassicly this plugin allows players to report bugs, so they can
    type /brp submit <Bug(One Word)> <Info(Unlimited Words)> and
    that would put a peice of paper in an inventory with the bug name
    and the extra info they put. So admins type /brp buglist, it opens a
    gui and all the bugs players have submited is in there.

    But when i go to reload/restart the server all the items from
    the /brp buglist gui disapear. So far what iv done is when
    people submit a bug it puts the info of the paper into a config (data.yml)
    but i dont know where to go from here....


    Thanks in advance

    ~ McGoNelson
  2. Try checking out this post of how to save/retrieve items from a config, I'm pretty sure there's a way to implement it in a custom config:

    EDIT: Changed to a probably more helpful link
  3. Don't see where you're actually doing anything with the values loaded from the configManager, looks like that might be in the file?

    Sent from my iPhone using Tapatalk
  4. Thanks for both of your replys!

    But ik how to store the gui item
    data to a config, but i want to know
    how id get it out of the data.yml when
    the plugin enables
  5. String someSetting = Config.getString("path");

    Sent from my iPhone using Tapatalk
  6. GuiItems:
    material: !!org.bukkit.Material 'PAPER'
    title: ยง9one
    - 'two three four five '

    Thats the data config when you make an item. Now how would i place that item back in the gui when the server starts?
  7. If you look at how you saved the object, like config.setWhatever(path,value);

    Reading it back in is just the opposite.
    value = Config.getWhatever(path);

    Sent from my iPhone using Tapatalk
  8. Code (Text):
    package me.GoNelson.BugReport;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class Main extends JavaPlugin implements Listener {
        private Inventory inv;
        ConfigManager settings = ConfigManager.getInstance();
        public void onEnable() {
            inv = Bukkit.getServer().createInventory(null, 9, ChatColor.BLUE + "Bug Report");
                Bukkit.getServer().getPluginManager().registerEvents(this, this);
                settings.getData().get("GuiItems." + args[1] + ".material", inv.addItem(paper));
                settings.getData().get("GuiItems." + args[1] + ".title", papermeta.setDisplayName(ChatColor.BLUE + args[1]);
                settings.getData().get("GuiItems." + args[1] + ".info", papermeta.setLore(lore);
                    public void onDisable() {
                    public void createItem(String ms, Inventory inv, String n, String lore, String lore1, int slot)
                            Material m = Material.getMaterial(ms.toUpperCase());
                            ItemStack stack = new ItemStack(m);
                            ItemMeta stackMeta = stack.getItemMeta();
                            stackMeta.setLore(Arrays.asList(new String[] { lore, lore1 }));
                            inv.setItem(slot, stack);
                    public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
                        if (!(sender instanceof Player)) {
                            sender.sendMessage("You have to be a player to use this command!");
                            return false;
                        Player player = (Player) sender;
                    if (cmd.getName().equalsIgnoreCase("brp") || cmd.getName().equalsIgnoreCase("bugreportplus")){
                            if (args.length == 0) {
                                    player.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.STRIKETHROUGH + "---------------" + "<" + ChatColor.RED + "Help" + ChatColor.DARK_GRAY + " (" + ChatColor.GRAY + "1/10" + ChatColor.DARK_GRAY + ")>" + ChatColor.STRIKETHROUGH + "---------------");
                                    player.sendMessage(ChatColor.GRAY + "/brp -" + ChatColor.RED + " opens this help menu");
                                    player.sendMessage(ChatColor.GRAY + "/brp submit <Bug> <info> -" + ChatColor.RED + " submits a bug report");
                                    player.sendMessage(ChatColor.GRAY + "/brp reload -" + ChatColor.RED + " reloads the config");
                                    player.sendMessage(ChatColor.GRAY + "/brp buglist -" + ChatColor.RED + " opens a gui with a list of bugs that players have reported");
                                    return true;
                            } else if (args[0].equalsIgnoreCase("reload")) {
                                if (player.hasPermission("brp.reload")) {
                                    player.sendMessage(ChatColor.BLUE + "You have reloaded the config!");
                                    return true;
                                } else {
                                    player.sendMessage(ChatColor.RED + "You dont have permission!");
                                    return false;
                            } else if (args[0].equalsIgnoreCase("buglist")) {
                                if (player.hasPermission("brp.buglist")) {
                                        return true;
                                } else {
                                    player.sendMessage(ChatColor.RED + "You dont have permission!");
                                    return false;
                            } else if (args[0].equalsIgnoreCase("submit")) {
                                if (args.length == 1) {
                                        player.sendMessage(ChatColor.RED + "USAGE: /brp submit <bug(one word)> <info(unlimited words)>");
                                } else if (args.length == 2) {
                                            player.sendMessage(ChatColor.RED + "USAGE: /brp submit <bug(one word)> <info(unlimited words)>");
                                        } else if (args.length >= 3) {  
                                            StringBuilder sb = new StringBuilder();
                                            for (int i = 2; i < args.length; i++)
                                                 sb.append(args[i]+" ");
                                            player.sendMessage(ChatColor.GREEN + "Bug Report Message Sent To Admin:");
                                            player.sendMessage(ChatColor.GREEN + "Title: " + ChatColor.BLUE + args[1]);
                                            player.sendMessage(ChatColor.GREEN + "Info: " + ChatColor.BLUE + sb);
                                            ItemStack paper = new ItemStack(Material.PAPER);
                                            ItemMeta papermeta = paper.getItemMeta();
                                            papermeta.setDisplayName(ChatColor.BLUE + args[1]);
                                            List<String> lore = new ArrayList<String>();
                                            lore.add("" + sb);
                                            settings.getData().set("GuiItems." + args[1] + ".material", paper.getType());
                                            settings.getData().set("GuiItems." + args[1] + ".title", papermeta.getDisplayName());
                                            settings.getData().set("GuiItems." + args[1] + ".info", papermeta.getLore());
                                        return true;
                                } else {
                                    player.sendMessage(ChatColor.RED + "Unknown argument, type /brp to show all the commands!");
                                    return false;
                    return false;
                    private int parse(String string) {
                        // TODO Auto-generated method stub
                        return 0;
    Thats now my code. In my onEnable it wont let me take the itemstack from below in the code. (Thanks for being patient with me :))
  9. Well in your onEnable that ItemStack probably doesent technically exist yet.

    If you were going to create one after reading in its variables from the config you would create a new ItemStack(type,1);
    And re create the lore and name as meta. You could save these completed items after they were loaded to a list or set in memory and when the GUI is re-opened add them

    Sent from my iPhone using Tapatalk
  10. I haven't looked in the code much yet, but I did notice you are missing a ) on this line in onEnable: settings.getData().get("GuiItems." + args[1] + ".info", papermeta.setLore(lore);

    EDIT: What are the 'paper' and 'lore' values? Are thoes like strings/materials? Or are they not even defined, which will definitly shoot out problems.
  11. That is a very good idea!
    but you need to get the args because the string is "GuiItems" + args[1] + "Material"
  12. Yea, ik thats an error but there was many other errors on it
  13. There aren't any errors in console from your plugin by any chance, are there?
  14. Error:
    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'brp' in plugin BugReportPlus v1.0.0
            at org.bukkit.command.PluginCommand.execute( ~[spigot.jar:git-Spigot-625bc00-41a7d14]
            at org.bukkit.command.SimpleCommandMap.dispatch( ~[spigot.jar:git-Spigot-625bc00-41a7d14]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand( ~[spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$ [spigot.jar:git-Spigot-625bc00-41a7d14]
            at java.util.concurrent.Executors$ Source) [?:1.8.0_121]
            at Source) [?:1.8.0_121]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C( [spigot.jar:git-Spigot-625bc00-41a7d14]
            at [spigot.jar:git-Spigot-625bc00-41a7d14]
            at Source) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity.openInventory( ~[spigot.jar:git-Spigot-625bc00-41a7d14]
            at me.GoNelson.BugReport.Main.onCommand( ~[?:?]
            at org.bukkit.command.PluginCommand.execute( ~[spigot.jar:git-Spigot-625bc00-41a7d14]
  15. So what are 'paper' and 'lore' defined as?

    EDIT: I just realized you have cmd arguments in the onEnable... not sure how that works, that might be a problem too. Do you have an IDE at all?
  16. You mean like eclipse? yes
  17. just throwing this in there, but
    this could be manipulated to have multiple lores:

    Code (Java):

    public void createItem(String ms, Inventory inv, String n, List<String> lore, int slot) {
                            Material m = Material.getMaterial(ms.toUpperCase());
                            ItemStack stack = new ItemStack(m);
                            ItemMeta stackMeta = stack.getItemMeta();
                            inv.setItem(slot, stack);

    public void example(Inventory inv) {
          createItem("ex", inv, "ex-arg2", Arrays.asList("loreline1, "loreline2"), 0);
  18. So can you tell me what the random args[] values are coming from, or 'paper' or 'lore'? They must be defined if you could compile it with an IDE with no errors.
  19. Hello everyone

    Thanks for all the replies. I have changed
    my code alot and from what i have found
    from all over the internet the code i have
    now should work. But for some reason it


    Thanks for your time