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.

    ITS A MINIGAME SO THE VAULTS SHOULD NOT BE SAVED WHEN SERVER STOPS.
     
  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

    hashmap
    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");
    PlayerInteractEvent
    Code (Java):
    if(pblock.getType() == Material.ENDER_CHEST) {
                    e.setCancelled(true);
                    pl.sendMessage(ChatColor.AQUA + "You have opened your locker!");
                    pl.openInventory(echest.get(pl));
                   
                }
     
  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
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:759) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_141]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?: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(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:176) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at me.finestaf.anniadd.Main.onBlockUse(Main.java:170) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_141]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_141]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_141]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 17 more
    >
     
     
  14. nvm i had to restart