Hashset adding location?

Discussion in 'Plugin Development' started by leland22, Apr 22, 2014.

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

    leland22

    I cant get the error that I'm getting. Could someone help? Its italicized. I'm trying to save the location of a block then reference it later.


    Code:java
    1. @EventHandler
    2. //Check to see if the player places a fletching stations. If they do it adds it to the location hashmap
    3. public void blockPlace(BlockPlaceEvent e){
    4. Player p = e.getPlayer();
    5. ItemStack item = p.getItemInHand();
    6. Block b = e.getBlock();
    7. Location loc = b.getLocation();
    8. String str = loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ();
    9. if(item.hasItemMeta()){
    10. if(item.getItemMeta().hasDisplayName()){
    11. if(item.getItemMeta().getDisplayName().contains("A fletching station")){
    12. [I]stations.add(str);[/I]
    13. }
    14. }
    15. }
    16. }
     
  2. Remove one of the
    }
     
  3. Offline

    leland22

  4. You are right I misread it.
    Where you define string str, try using String.valueOf (loc.getBlockX/Y/Z()) for the three numbers

    Also please show where you define the hashmap

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

    Wizehh

    What error does this code produce? We can't help you unless you provide a stacktrace or you clarify your question.
     
  6. Offline

    leland22

  7. Offline

    Wizehh

  8. Offline

    leland22

    Wizehh
    Code:java
    1. package leland22.plugins;
    2.  
    3. import java.util.HashMap;
    4. import java.util.HashSet;
    5. import java.util.Map;
    6.  
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.block.Action;
    14. import org.bukkit.event.block.BlockPlaceEvent;
    15. import org.bukkit.event.player.PlayerInteractEvent;
    16. import org.bukkit.inventory.ItemStack;
    17.  
    18. public class ActionListener implements Listener{
    19. ArrowBench abench = new ArrowBench();
    20.  
    21. public HashSet<Location> stations = new HashSet<Location>();
    22.  
    23. public ActionListener(ArrowBench plugin) {
    24. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    25.  
    26. }
    27. //Checks if the player is able to turn blocks into fletching stations then adds the block to the list
    28. @EventHandler
    29. public void onLeftClick(PlayerInteractEvent e){
    30. Player p = e.getPlayer();
    31. if(e.getAction()==Action.RIGHT_CLICK_BLOCK){
    32. Block b = e.getClickedBlock();
    33. if(b.getType().equals(Material.WORKBENCH)){
    34. if(ArrowBench.fletcher.contains(p.getName())){
    35. Location loc = b.getLocation();
    36. stations.add(loc);
    37.  
    38. }
    39. }
    40. }
    41. }
    42. @EventHandler
    43. //Check to see if the player places a fletching stations. If they do it adds it to the location hashmap
    44. public void blockPlace(BlockPlaceEvent e){
    45. Player p = e.getPlayer();
    46. ItemStack item = p.getItemInHand();
    47. Block b = e.getBlock();
    48. Location loc = b.getLocation();
    49. String str = loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ();
    50. if(item.hasItemMeta()){
    51. if(item.getItemMeta().hasDisplayName()){
    52. if(item.getItemMeta().getDisplayName().contains("A fletching station")){
    53. stations.add(str);
    54. }
    55. }
    56. }
    57. }
    58. //Opens the GUI if the workbench is on the list
    59. @EventHandler
    60. public void openWorkbench(PlayerInteractEvent e){
    61. Player p = e.getPlayer();
    62. Block b = e.getClickedBlock();
    63. Location loc = b.getLocation();
    64. if(e.getAction().equals(Action.LEFT_CLICK_BLOCK))
    65. if(b.getType().equals(Material.WORKBENCH)){
    66. if(stations.contains(loc)){
    67. p.sendMessage("YAY!");
    68. }
    69. }
    70. }
    71. }
    72.  
     
  9. Offline

    Rocoty

    And tell us again why you think adding a String to a Set of Locations would work?
     
  10. Offline

    leland22

    Rocoty
    I have no clue how to do this, I keep asking for help but I just get vague advice.
     
  11. Offline

    Rocoty

    leland22 that is because you should already know what you are doing. Making bukkit plugins assumes basic Java knowledge.
     
Thread Status:
Not open for further replies.

Share This Page