Solved When a player right clicks block vault is opened

Discussion in 'Spigot Plugin Development' started by DatsMaboi, May 31, 2018.

  1. So i want players to have a personal vote with 9 slots. They open it by right clicking on a block.i heard you can use hashmaps but idk how to use them.

  2. Create a global hashmap<player, inventory> and onEnable loop through all online players and create them a 1 row inventory. Afterwards you should implement listener and listen on the PlayerInteractEvent. If the player right clicks a block then you should get that hashmap and open the Inventory for the player. player.openInventory( HashMap.get(player) ) . If you wish you could also listen onPlayerJoin and create an inventory then as well. Quite simple.
    #2 darklazerog, May 31, 2018
    Last edited: May 31, 2018
  3. I dont know how to use a hashmap or make one thats the bit i don't get
    • Funny Funny x 2
  4. [​IMG]

    Yeah. Sorry. Had to put that there.
    • Agree Agree x 1
    • Funny Funny x 1
  5. Just visit this page... Try google next time ;)

    I think you should be worried if you're creating a minigame without knowing how to use a HashMap.
  6. @DatsMaboi according to your thread posting history, you shouldn't be making Spigot plugins in first place. Go learn the fundamentals of Java before you try to request help. You literally have 109 threads, sometimes asking the simpliest things.
    • Agree Agree x 1
  7. ok i understand how to make a hashmap and open the inventory but how do i create it where do i put it
  8. So I see some people doing as @DarkSeraphim and others would call spoon feeding this information to you and the others giving you advice, but no guidance.

    It is neat to be able read and copy and paste code to get spigot to do some cool stuff. But its even neater to understand exactly whats happening(Be it that the code is conventional).

    When I started making client mods and delving into Java back in 2014 a friend sent me these old Stanford tutorials which explained the fundamentals of java.

    Now don't skip around and all that but watch every second of those videos and follow along. You should be ready to learn the Spigot/Bukkit Api which you can find the javadocs here and here is a good place to find entry snippets to teach you a little bit about the flow of a basic plugin.
  9. hold on let me open my ide for you and get to work.

    you need to learn the basics of java 1st

    for us to answer your question we might as well code it for you.

    but as for how to create the inventoy
    start by typing Bukkit.

    also google: spigot java docs
    • Useful Useful x 1
  10. no i know how to make a gui thats easy but i dont get where it comes with hashmap
  11. This is what i did

    Code (Java):
    public HashMap<Player, Inventory> echest = new HashMap<Player, Inventory>();
    Player Join Event
    Code (Java):
    Bukkit.createInventory(p, 9, ChatColor.AQUA + p.getName() + ChatColor.AQUA + "'s locker");
    Code (Java):
    if(pblock.getType() == Material.ENDER_CHEST) {
                    pl.sendMessage(ChatColor.AQUA + "You have opened your locker!");
  12. Am i doing the right thing? or am i missing something somewhere???
    • Winner Winner x 1
  13. Code (Text):
    [15:15:06 ERROR]: Could not pass event PlayerInteractEvent to AnniNEXAddons v1.0
        at$1.execute( ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$ [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$ [?:1.8.0_141]
        at [?:1.8.0_141]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A( [spigot.jar:git-Spigot-db6de12-18fbb24]
        at [spigot.jar:git-Spigot-db6de12-18fbb24]
        at [?:1.8.0_141]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity.openInventory( ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at me.finestaf.anniadd.Main.onBlockUse( ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]
        at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_141]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_141]
        at java.lang.reflect.Method.invoke( ~[?:1.8.0_141]
        at$1.execute( ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 17 more
  14. nvm i had to restart