Development Assistance GUI Menu problem

Discussion in 'Plugin Help/Development/Requests' started by dragonlord25, Feb 26, 2015.

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

    dragonlord25

    Hello I have been having problems trying to code a GUI Menu that shows players kills, deaths, and balance

    Every time i used the right coding i would get an error in my server console?
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    dragonlord25

    well the server log has it private so i can't see it in the servers log but here is its coding that i have.



    package me.SmokieBear.Hub2;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;

    public class InvGui implements Listener {

    public InvGui(Main Plugin) {
    }

    Inventory inv;

    public void openInventory(Player p) {
    inv = Bukkit.getServer().createInventory(null, 9, ChatColor.BLUE + "Custom Inv");
    p.openInventory(inv);
    inv.setItem(8, new ItemStack(Material.DIAMOND));
    }

    @EventHandler
    public void itemClick(InventoryClickEvent event){
    if(event.getInventory().getName().equalsIgnoreCase(ChatColor.BLUE + "Custom Inv")){
    if(event.getInventory()== null) {
    return;
    }
    event.setCancelled(true);
    if(event.getCurrentItem().equals(new ItemStack(Material.DIAMOND))){
    Player p = (Player) event.getWhoClicked();

    p.closeInventory();
    p.sendMessage("Works.");

    }
    }

    }

    }
     
  4. Offline

    hammy2899

    if(event.getCurrentItem().equals(new ItemStack(Material.DIAMOND))){
    change to
    if(event.getCurrentItem().getType().equals(Material.DIAMOND)){
     
  5. Offline

    dragonlord25

    i tried that and i still got an error because its not wanting to run its /inv command as well
     
  6. Offline

    Ruptur

    @dragonlord25
    Its always helpful to have your server logs since the stack trace tells you exactly where your problem is
    You can run a server on your local network so you can test your plugins.
     
  7. Offline

    dragonlord25

    heres its main file
    package me.SmokieBear.Hub2;

    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin {

    public Main Plugin;
    public final Logger logger = Bukkit.getServer().getLogger();

    @Override
    public void onEnable(){
    this.getServer().getPluginManager().registerEvents(new InvGui(this), this);
    this.getCommand("inv").setExecutor(new Commands(new InvGui(this)));
    }

    }

    then heres the commands file code
    package me.SmokieBear.Hub2;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Commands extends JavaPlugin {

    private final InvGui gui;

    public Commands(InvGui gui) {
    this.gui = gui;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {

    if(!(sender instanceof Player)) {
    return true;
    }

    if(args.length !=0){
    return true;
    }
    Player p = (Player) sender;

    gui.openInventory(p);
    p.sendMessage(ChatColor.GRAY + "Opened inv.");

    return false;

    }

    }

    well the server host company i go through has the file set to private so i can't open it at all even through filezilla

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  8. Offline

    _Filip

    we cant help you unless you give us your server logs

    EDIT: Test the plugin locally or get a better server host
     
  9. Offline

    dragonlord25

    Error occurred while enabling Hub2 v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at me.SmokieBear.Hub2.Commands.<init>(Commands.java:13) ~[?:?]
    at me.SmokieBear.Hub2.Main.onEnable(Main.java:14) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:341) [craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:484) [craftbukkit.jar:git-Bukkit-e81edfc]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.IllegalStateException: Initial initialization
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at me.SmokieBear.Hub2.Main.<init>(Main.java:6) ~[?:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_31]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_31]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_31]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_31]
    at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_31]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:288) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.<init>(CraftServer.java:250) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.PlayerList.<init>(PlayerList.java:69) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.DedicatedPlayerList.<init>(SourceFile:14) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:133) ~[craftbukkit.jar:git-Bukkit-e81edfc]
    ... 2 more
    [14:37:15] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it


    would that help at all

    i copied that from the server console from the host company but was a pain in the butt

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 28, 2015
  10. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
    @dragonlord25 Please use this for code: [syntax=java] < code here > [/syntax] Makes it way easier to read.
    For logs: [code] < log here > [/code]
    Or pastebin
    Also: Only 1 class can extend JavaPlugin
     
  11. Offline

    dragonlord25

    so only like the Main or the other 2?
     
  12. Online

    timtower Administrator Administrator Moderator

    @dragonlord25 Only the main should extend it. And also please use the tahg or reply button when responding to somebody.
     
  13. Offline

    dragonlord25

    Code:java
    1.  
    2. package com.SmokieBear.Hub3;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8.  
    9.  
    10. public class Commands {
    11.  
    12. private final InvGui gui;
    13.  
    14. public Commands(InvGui gui) {
    15. this.gui = gui;
    16. }
    17.  
    18. @Override
    19. public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
    20.  
    21. if(!(sender instanceof Player)) {
    22. return true;
    23. }
    24.  
    25. if(args.length !=0){
    26. return true;
    27. }
    28. Player p = (Player) sender;
    29.  
    30. gui.openInventory(p);
    31. p.sendMessage(ChatColor.GRAY + "Opened inv.");
    32.  
    33. return false;
    34.  
    35. }
    36.  
    37. }
    38.  


    but it comes with the an error on line 19

    EDIT by Timtower: merged posts
     
  14. Online

    timtower Administrator Administrator Moderator

    @dragonlord25 Probably because it isn't implement CommandExecutor.
    Hovering your mouse over the error tells the error most of the time.
     
  15. Offline

    dragonlord25

    well i removed the @Override but when i run it still it comes up with this
    Code:
    java.lang.ClassCastException: com.SmokieBear.Hub3.Commands cannot be cast to org.bukkit.command.CommandExecutor
        at com.SmokieBear.Hub3.Main.onEnable(Main.java:16) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit.jar:git-Bukkit-e81edfc]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit.jar:git-Bukkit-e81edfc]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-e81edfc]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:341) [craftbukkit.jar:git-Bukkit-e81edfc]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [craftbukkit.jar:git-Bukkit-e81edfc]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit.jar:git-Bukkit-e81edfc]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit.jar:git-Bukkit-e81edfc]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit.jar:git-Bukkit-e81edfc]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit.jar:git-Bukkit-e81edfc]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:484) [craftbukkit.jar:git-Bukkit-e81edfc]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    [15:22:57] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    
     
    Code:java
    1.  
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. public class Main extends JavaPlugin {
    9.  
    10. public Main Plugin;
    11. public final Logger logger = Bukkit.getServer().getLogger();
    12.  
    13. @Override
    14. public void onEnable(){
    15. this.getServer().getPluginManager().registerEvents(new InvGui(this), this);
    16. this.getCommand("inv").setExecutor((CommandExecutor) new Commands(new InvGui(this)));
    17. }
    18.  
    19.  
    20.  
    21. @Override
    22. public void onDisable(){
    23.  
    24. }
    25.  
    26. }
    27.  

    what would i need to change to this.getCommand("inv").setExecutor((CommandExecutor) new Commands(new InvGui(this)));

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 28, 2015
  16. Offline

    pie_flavor

    @dragonlord25
    You need to make your command class implement CommandExecutor. That's what the @Override error was telling you, that it's not overriding anything. Casting it to CommandExecutor while registering it won't work and won't do anything.
    Alternatively, if you are using Java 8, you can say
    Code:java
    1. getCommand("inv").setExecutor(new Commands(new InvGui(this)):: onCommand);

    and then name the method whatever you want as long as you reflect those changes in the register. For more information, click here.
    Also, a couple more pointers:
    Don't say this.getServer() or this.getCommand(). Useless. Just say getServer() or getCommand().
    If InvGui is what I think it is, it'd be better to use the same InvGui instance in both registerEvents() and new Commands().
    That's a mighty big line of code there to get the logger. A: You never use it, and B: you can literally just type getLogger().
     
    Last edited: Feb 28, 2015
  17. Offline

    dragonlord25

    um dude u don't make since what so ever
     
  18. Offline

    pie_flavor

    @dragonlord25 Please, elaborate.
    EDIT: Apparently ': o' without the space parses to :eek:.
     
  19. Offline

    dragonlord25

    um i don't see A anywhere in my coding

    k guys i re-did another file thats just one file for InventoryGUI
    Code:java
    1.  
    2. import org.bukkit.Bukkit;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.inventory.InventoryClickEvent;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.event.player.PlayerJoinEvent;
    13. import org.bukkit.inventory.Inventory;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class InventoryGUI extends JavaPlugin implements Listener {
    19.  
    20. public void onEnable(){
    21. getServer().getPluginManager().registerEvents(this, this);
    22.  
    23. }
    24.  
    25. private void teleportinWord(Player player, int x, int y, int z) {
    26. player.teleport(new Location(player.getWorld(), x, y, z));
    27. }
    28.  
    29. private void openGUI(Player player) {
    30. Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Select A Server");
    31.  
    32. ItemStack survival = new ItemStack (Material.DIAMOND_SWORD);
    33. ItemMeta survivalMeta = survival.getItemMeta();
    34. ItemStack creative = new ItemStack (Material.GRASS);
    35. ItemMeta creativeMeta = creative.getItemMeta();
    36. ItemStack faction = new ItemStack (Material.BOW);
    37. ItemMeta factionMeta = faction.getItemMeta();
    38. ItemStack parkour = new ItemStack (Material.LAVA);
    39. ItemMeta parkourMeta = parkour.getItemMeta();
    40.  
    41. survivalMeta.setDisplayName(ChatColor.RED + "Survival");
    42. survival.setItemMeta(survivalMeta);
    43.  
    44. creativeMeta.setDisplayName(ChatColor.GREEN + "Creative");
    45. creative.setItemMeta(creativeMeta);
    46.  
    47. factionMeta.setDisplayName(ChatColor.BLUE + "Faction");
    48. faction.setItemMeta(factionMeta);
    49.  
    50. parkourMeta.setDisplayName(ChatColor.GOLD + "Parkour");
    51. parkour.setItemMeta(parkourMeta);
    52.  
    53. inv.setItem(2, survival);
    54. inv.setItem(3, creative);
    55. inv.setItem(4, faction);
    56. inv.setItem(5, parkour);
    57.  
    58. player.openInventory(inv);
    59.  
    60. }
    61.  
    62. @EventHandler
    63. public void onInventoryClick(InventoryClickEvent event) {
    64. if(!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Server Selector"))
    65. return;
    66. Player player = (Player) event.getWhoClicked();
    67. event.setCancelled(true);
    68.  
    69. if(event.getCurrentItem()==null || event.getCurrentItem().getType()==Material.AIR||!event.getCurrentItem().hasItemMeta()) {
    70. player.closeInventory();
    71. return;
    72. }
    73.  
    74. switch(event.getCurrentItem().getType()) {
    75. case DIAMOND_SWORD:
    76. teleportinWord(player, 0, 50, 0);
    77. player.closeInventory();
    78. player.sendMessage(String.format("%sTeleported to %sSurvival%s", ChatColor.GOLD,ChatColor.RED,ChatColor.GOLD));
    79.  
    80. break;
    81. case GRASS:
    82. teleportinWord(player, 20, 50, 20);
    83. player.closeInventory();
    84. player.sendMessage(String.format("%sTeleported to %sCreative%s", ChatColor.GOLD,ChatColor.GREEN,ChatColor.GOLD));
    85.  
    86. break;
    87. case BOW:
    88. teleportinWord(player, 30, 50, 30);
    89. player.closeInventory();
    90. player.sendMessage(String.format("%sTeleported to %sFactions%s", ChatColor.GOLD,ChatColor.BLUE,ChatColor.GOLD));
    91.  
    92. break;
    93. case LAVA:
    94. teleportinWord(player, 40, 50, 40);
    95. player.closeInventory();
    96. player.sendMessage(String.format("%sTeleported to %sParkour%s", ChatColor.GOLD,ChatColor.GOLD,ChatColor.GOLD));
    97.  
    98. break;
    99. default:
    100. player.closeInventory();
    101. break;
    102. }
    103. }
    104.  
    105.  
    106. @EventHandler
    107. public void onPlayerJoin(PlayerJoinEvent event) {
    108. event.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS));
    109. }
    110.  
    111. @EventHandler
    112. public void onPlayerInteract(PlayerInteractEvent event) {
    113. Action a= event.getAction();
    114. ItemStack is = event.getItem();
    115.  
    116. if(a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
    117. return;
    118.  
    119. if(is.getType() == Material.COMPASS)
    120. openGUI(event.getPlayer());
    121. }
    122.  
    123.  
    124.  
    125. }
    126.  
    127.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  20. Offline

    pie_flavor

    @dragonlord25 Still an unhelpful response, and by A: and B: I meant like two things.
     
Thread Status:
Not open for further replies.

Share This Page