Inventory Minigames [need help creating]

Discussion in 'Plugin Development' started by Unfooishly, Apr 17, 2014.

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

    Unfooishly

    Hi, so a while back I was playing on a Noxcrew's server called MCStrike and I notice they have mini games on a pda that when you right click it open the inventory and you play games on it (MineSweeper for instance). Recently I came across a SethBling Video in which he showcased a plugin(BlingJeweled) he made which allows the player to play Bejeweled when the player right clicks on an emerald.

    I'm wondering what makes it possible to do that and how its done. Thank you guys for your time:D.
     
  2. Offline

    TryB4

    Unfooishly
    You can decompile it and learn from it's source
     
  3. Offline

    TheMcScavenger

    There's a few things you need to code in order to achieve this:
    • Register the OnPlayerInteractEvent, and get the item the player has in his hand.
    • Register the InventoryClickEvent, and get the slot / item the player clicked on
    • Create an inventory
    • Set the items in the inventory, possibly using a randomiser
    When the player right clicks the item you specified, he / she will be presented with the inventory. You will then need the other event (InventoryClickEvent), to specify what you want to do when a player clicks on an item in the inventory (e.g. add a potion effect to it & cancel the event).
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerInteract(PlayerInteractEvent event){
            Player player = event.getPlayer();
            if(event.getAction().equals(Action.RIGHT_CLICK_AIR) && player.getItemInHand().equals(Material.EMERALD)){
                // Check for permissions if you want to
                // Send the player a message if you want to
                // Open the Inventory
            }
        }
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerInteract(InventoryClickEvent event){
            if(event.getInventory().getTitle().equals("Your Inventory Name")){
                Player player = (Player) event.getWhoClicked();
               
                // Get the item, and do with it what you want
            }
        }
     
  4. Offline

    Unfooishly

    I'll try that and see what happens

    how do I decompile it?

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

    TheMcScavenger

    You download the plugin, open it up with any program that can be used to open up a .jar file, locate the .class files, and look in those with a program as JD-GUI.
     
  6. Offline

    TryB4

    Unfooishly
    1. download win-rar or 7zip
    2. Open the plugin's jar file with either.
    3. download JD-GUI
     
  7. Offline

    Unfooishly

    TryB4 and TheMcScavenger ok the jd-gui works so i found i need to learn how to code... Do you guys any good person i can learn that from in youtube?
     
  8. Offline

    Garris0n

  9. Offline

    Unfooishly

    Garris0n I meant how to use hash code sorry didnt notice I forgot a few words. I already know code a bit considering one bukkit plugin and still making another and at the same time making a Minecraft mod.


    [ NOTE TO SELF START REVISING BEFORE POSTING ANYTHING.]
     
  10. Offline

    Garris0n

    How to use hash code? Like... the hashCode() method?
     
  11. Offline

    TheMcScavenger




    I myself have watched the 80 videos of TheBZBroz, and I must say it really helped me out in the beginning. All the basics are covered, meaning that once you've watched all of those, you can start making plugins right away.
     
  12. Offline

    gopro_2027

    heres the video that helped me code my gta plugin (maybe going to be on bukkit dev). youtube video you can basically use his code for any type of inventory. just one thing i would like to add: it is possible to still shift click and close the inventory to get an item even though it is extremely hard to do. you can use this even listener to make it so whenever he clciks with this item in his hand it goes away. heres the extra event listener:
    Code:java
    1. public static ItemStack exampleitem; //you can later define the properties of this item
    2. @EventHandler
    3. public void onPlayerInteractEvent(PlayerInteractEvent pie) throws IOException {
    4. ItemStack iih = (ItemStack) pie.getPlayer().getItemInHand();
    5. if(iih.equals(exampleitem)) {
    6. pie.getPlayer().setItemInHand(null);
    7. pie.setCancelled(true);
    8. }
    9. }

    hope this helps!
     
Thread Status:
Not open for further replies.

Share This Page