[Solved] Problem With The Config

Discussion in 'Programming' started by tomerkenis, Jun 1, 2017.

  1. Does anyone know why the main.reports.set("something", "something"); is not working?
    Code (Text):

    public static File reportsFile;
    public static FileConfiguration reports;

    public void onEnable() {
            if (!getDataFolder().exists()) {
                getDataFolder().mkdirs();
            }
            reportsFile = new File(this.getDataFolder(), "reports.yml");
            reports = YamlConfiguration.loadConfiguration(reportsFile);
            if (!reportsFile.exists())
                try {
                    reportsFile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                 main.reports.set("something", "something");
                    try {
                        main.reports.save(main.reportsFile);
                    } catch (IOException ec) {
                        ec.printStackTrace();
                    }
    }



     
     
  2. Why main. in front of the commands, also, does it print a stack trace?
     
  3. I'm assuming your main class is the one you are currently using with onEnable() so how about doing
    Code (Java):
    this.reports.set("","");
     
  4. i put the main in the main.reports.set("something", "something"); because originaly it is in another class
     
  5. okay so how do you get the instance of main class? and then how you define reports() { in main class.
     
  6. i need to do it like this?:
    Code (Text):
    main instance;
      public static main getInstance() {
            return instance;
        }
    main.getInstance().reports.set(reportedName, hackType);
     
    cuz i am just doing
    main.reports.set(reportedName, hackType);
    without the getinstance method
     
  7. well at your first sent you only do :
    Code (Java):
    main.reports.set("something", "something");
    try getting the main instance
    Code (Java):
    main.getInstance().reports........
     
  8. what you suggested did not work


    13:44:43] [Server thread/ERROR]: Could not pass event InventoryClickEvent to ReporterPro v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1839) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_131]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_131]
    at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
    Caused by: java.lang.IllegalArgumentException: Cannot set to an empty path
    at org.apache.commons.lang.Validate.notEmpty(Validate.java:321) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at org.bukkit.configuration.MemorySection.set(MemorySection.java:167) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    at com.tomerkenis.reporter.onInvClick.onInvClickEvent(onInvClick.java:55) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_131]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_131]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-c918638]
    ... 15 more

    this is the error that its giving me in the server in both what i did and what you suggested
     
  9. can you show us the code the error persist at line
    Code (Java):
    onInvClick.java:55
    will you show us the line 55 at oninvclick?
     
  10. main.reports.set(reportedName, hackType);
    or in what you suggested
    main.getInstance().reports.set(reportedName, hackType);

    reportedName and hackType are strings
     
    #10 tomerkenis, Jun 1, 2017
    Last edited: Jun 1, 2017
  11. I'm not asking for that, I'm asking for will you show your onInvClick class with line 55?
     
  12. Code (Text):
    package com.tomerkenis.reporter;

    import java.io.File;
    import java.io.IOException;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin {
        static main instance;

        public static main getInstance() {
            return instance;
        }

        @SuppressWarnings("static-access")
        static Inventory rpgui = Bukkit.createInventory(null, 18, ChatColor.BLACK.BOLD + "Report");
        static Inventory confirmgui = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Are You Sure?");

        static void reporterGUI() {
            ItemStack killAura = new ItemStack(Material.SKULL_ITEM, 1);
            ItemMeta imkillAura = killAura.getItemMeta();
            imkillAura.setDisplayName(ChatColor.YELLOW + "KillAura");
            killAura.setItemMeta(imkillAura);
            rpgui.setItem(0, killAura);

            ItemStack abuse = new ItemStack(Material.BLAZE_ROD, 1);
            ItemMeta imAbuse = abuse.getItemMeta();
            imAbuse.setDisplayName(ChatColor.YELLOW + "Staff Abuse");
            abuse.setItemMeta(imAbuse);
            rpgui.setItem(1, abuse);

            ItemStack fly = new ItemStack(Material.FIREWORK, 1);
            ItemMeta imFly = fly.getItemMeta();
            imFly.setDisplayName(ChatColor.YELLOW + "Fly");
            fly.setItemMeta(imFly);
            rpgui.setItem(2, fly);

            ItemStack speed = new ItemStack(Material.POTION, 1);
            ItemMeta imSpeed = speed.getItemMeta();
            imSpeed.setDisplayName(ChatColor.YELLOW + "Speed");
            speed.setItemMeta(imSpeed);
            rpgui.setItem(3, speed);
        }

        static Inventory getReporterGUI() {
            reporterGUI();
            return rpgui;
        }

        static void confirmGUI() {
            ItemStack confirm = new ItemStack(Material.WOOL, 1, (short) 5);
            ItemMeta imConfirm = confirm.getItemMeta();
            imConfirm.setDisplayName(ChatColor.GREEN + "Confirm");
            confirm.setItemMeta(imConfirm);
            confirmgui.setItem(0, confirm);

            ItemStack cancel = new ItemStack(Material.WOOL, 1, (short) 14);
            ItemMeta imCancel = cancel.getItemMeta();
            imCancel.setDisplayName(ChatColor.RED + "Cancel");
            cancel.setItemMeta(imCancel);
            confirmgui.setItem(8, cancel);

        }

        static Inventory getConfirmGUI() {
            confirmGUI();
            return confirmgui;
        }

        public static File reportsFile;
        public static FileConfiguration reports;

        @Override
        public void onEnable() {
            if (!getDataFolder().exists()) {
                getDataFolder().mkdirs();
            }
            reportsFile = new File(this.getDataFolder(), "reports.yml");
            reports = YamlConfiguration.loadConfiguration(reportsFile);
            if (!reportsFile.exists())
                try {
                    reportsFile.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            getServer().getPluginManager().registerEvents(new onInvClick(), this);
            getCommand("report").setExecutor(new onInvClick());
        }

        @Override
        public void onDisable() {
            try {
                reports.save(reportsFile);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
     
  13. oh well you do not have to use static on all methods except getInstance().
     
  14. its not the right class i am an idiot
     
  15. Code (Text):
    package com.tomerkenis.reporter;

    import java.io.IOException;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;

    public class onInvClick implements Listener, CommandExecutor {
        String reportedName;
        String hackType;

        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (label.equalsIgnoreCase("report")) {
                Player p = (Player) sender;
                if (sender instanceof Player) {
                    if (args.length != 0) {
                        reportedName = args[0];
                        p.sendMessage(ChatColor.GRAY + "Opening Report GUI....");
                        p.openInventory(main.getReporterGUI());

                    } else {
                        p.sendMessage(ChatColor.RED + "/report <Player Name>");
                    }
                } else {
                    sender.sendMessage(ChatColor.RED + "&eYou need to be a player to execute this command!");
                }

            }
            return false;
        }

        @EventHandler
        public void onInvClickEvent(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
            if (e.getInventory().equals(main.getReporterGUI())) {
                String hackType = e.getCurrentItem().getItemMeta().getDisplayName().toLowerCase();
                this.hackType = hackType;
                e.setCancelled(true);
                player.closeInventory();
                player.openInventory(main.getConfirmGUI());
            }
            if (e.getInventory().equals(main.getConfirmGUI())) {
                switch (e.getSlot()) {
                case 0:
                    e.setCancelled(true);
                    player.closeInventory();
                    player.sendMessage(ChatColor.GREEN + "You succsesfuly reported this player!");
                    main.reports.set(reportedName, hackType);
                    try {
                        main.reports.save(main.reportsFile);
                    } catch (IOException ec) {
                        ec.printStackTrace();
                    }

                    break;

                case 8:
                    e.setCancelled(true);
                    player.closeInventory();
                    hackType = null;
                    break;
                }
            }
        }
    }
     
     
  16. Mas

    Mas

    Look at the error: "Cannot set empty path".
     
  17. thank you,yes,that was the problem now it is working