Warps Gui Help

Discussion in 'Spigot Plugin Development' started by nicoxdry, Jun 6, 2017.

  1. Ive been trying to make a Warps gui plugin but i haven't been able to make it work

    Code:
    https://pastebin.com/kiNjzcrW (Couldn't post code here because its more than 20000 characters)

    This is my plugin.yml
    Code (Text):
    name: WarpsGui
    main: me.nicoxdry.com.WarpGui
    version: '1.10.2'
    commands:
      Warps:
        description: warps gui
        usage: /<command>
        aliases: [Warp, ewarps]
     
  2. what does not work
     
  3. When i type /Warp it sends an error in console and an error in game aswell
     
  4. can you post it
     
  5. I don't have the error log atm i have it on my test server (server.pro) so i have to wait for queue. I remember it was something about human entity error in the creation for the inventory but i don't remember correctly.
     
  6. One thing i can think of when something in that code goez wrong with human entitie is that the entitie who clicks doesn't have to be a player instance. I suggest you try to check first if it is a player. It is not something i think should go wrong, but you can never be certain.
     
  7. What do you mean?
     
  8. You cast the whoClicked() to a Player, but it can be a HumanEntity
     
  9. Im using this Player p = (Player) e.getWhoClicked(); then i do p.openInventory(inv); to open ins idk which is the problem and i got no problems pop up in the code.
     
  10. As i said, i dont think it is an problem but event.getWhoClicked() returns a HumanEntity object, not a Player. Player is a class thay extends HumanEntity.
     
  11. So how could i fix that?
     
  12. check if it is a player before casting
     
  13. please, please make this in an OOP manner. it would make everything much more easier to interpret and in the end, make everything much more manageable.

    also, some very easy things you could optimize and replace in here. breaking usage of DRY principle at times as well.

    separate your classes into different packages and locations to organize yourself.

    dont blindly cast to objects.

    use proper naming conventions

    Code (Text):

    openGUI1(Player player) {
           
    }

    openGUI2(Player player) {
           
    }
     
    name such methods to things that make sense. (openDonorMenu, openWarpMenu) even then, you could create GUI objects which pertain information(inventory contents, title, etc).

    Code (Java):

    public class Warp {

          private String name;
          private ItemStack icon;
          private String command;

          public Warp(String name, ItemStack icon, String command) {
                 this.name = name;
                 this.icon = icon;
                 this.command = command;
          }

          //getters & setters
    }
     
    #13 ChefJava, Jun 6, 2017
    Last edited: Jun 6, 2017
    • Like Like x 1
  14. looks like a plugin with the same id has already been registered. Are you sure you have only 1 instance of your plugin in the plugins folder
     
  15. Yes theres only 1 instance of my plugin in the folder
     
  16. As ChefJava said please clean up your code and make objects instead cause no offense but this looks kind of messy.
     
  17. Ok ty for helping