How can I Place water based on my position?

Discussion in 'Plugin Development' started by Thomas117, Jan 4, 2018.

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

    Thomas117

    I am trying to make a plugin that does different thing based on clicking different items. I am trying to place a water block in the area that I click, but I am not sure how to go about doing this. this is what I have so far
    @EventHandler
    public void onPlayerInteract1(PlayerInteractEvent e) {
    Action a = e.getAction();
    ItemStack is = e.getItem();

    if(a == Action.RIGHT_CLICK_AIR || is == null || is.getType()==Material.AIR)
    return;

    if(is.getType() == Material.LAPIS_BLOCK)

    }
     
  2. Offline

    Drkmaster83

    So if they left click or right click with a lapis block, you want to create water? Doesn't seem quite right.
    Regardless, this event has e.getClickedBlock(), but you need to check if it's null as well.
     
  3. Offline

    Thomas117

    Okay, but how do I place the water?
     
  4. Offline

    Drkmaster83

    Well, depends on if you want the clicked block to become water or if you want the lapis block that you place to become water.
     
  5. Offline

    Thomas117

    I want the air above the clicked block to become water.

    Also I am selecting the lapis block from a GUI. Is there a way to have it remember the second to last item that was clicked? I want to select the item from the GUI, then use the main item to actually perform the task.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 5, 2018
  6. Offline

    Max8801

    Code:java
    1.  
    2. if(e.getClickedBlock() != null)
    3. e.getClickedBlock().getRelative(BlockFace.UP).setType(Material.WATER);
    4.  

    Create a HashMap that maps the player's name to an ItemStack. When the player clicks an item in the gui, put him along with the item he had selected before into the HashMap. Now either the second last item is stored in the map or the player is not in the HashMap if he has not selected an item before.
    Could you please explain that a little better?
     
    Last edited: Jan 5, 2018
  7. Offline

    Thomas117

    I have a GUI setup with different Items to represent the things that I want the "main item" (what I use to open the GUI)
    to do. After selecting the item in the GUI, I want it close and I want to be able to use the ability from the item that I choose by right clicking with the "main item" in my hand.
     
    Last edited: Jan 5, 2018
  8. Offline

    Max8801

    Ah, okay, I understand. Should the main item change in any way or should it stay exactly the same (e.g. Material, name, lore)?
     
  9. Offline

    Thomas117

    No it is just a Wood Axe
     
  10. Offline

    Max8801

    Okay, then simply use a HashMap that maps the player's name or uuid to the ability he chose (e.g. Enum).
     
  11. Offline

    Thomas117

    How do I make a HashMap that does that?
     
  12. Offline

    Max8801

    That is a basic thing in Java. May I suggest a quick Google search? I don't want to seem rude but this is no place for questions related to Java basics.
     
  13. Offline

    Thomas117

    I can't find how to map to an item. could you give me more info on what I should search for?
     
    Last edited: Jan 5, 2018
  14. Offline

    Max8801

    Well, "Java HashMap tutorial" would be a good start
     
  15. Offline

    Thomas117

    I have looked through 15 different links, and I have made little progress. Could I please have some help?
     
  16. Offline

    Max8801

    Alright, what exactly are you stuck with. Please provide me with exact questions other than "Could you please give me an examle?".
     
  17. Offline

    Thomas117

    How do I make my GUI items the things that it maps?
     
  18. Offline

    Max8801

    By using a HashMap that maps a player's name or UUID to the ability they selected. For the ability, I suggest the use of an enum. When a player clicks on an item, put him along with the corresponding enum entry into the HashMap.

    If the links to the tutorials I provided you with can't help you, you should consider learning or revising the fundamentals of Java before trying to use the Bukkit API.
     
Thread Status:
Not open for further replies.

Share This Page