Door hashcode is different depending on who is toggling it

Discussion in 'Spigot Plugin Development' started by BadBoy6767, Jan 10, 2017.

  1. I have a Door instance taken from Block.getState().getData().
    I am putting these doors in a map (K=Door,V=Value). (As in each door has an owner).

    I have noticed that the hash code for the Door instance is different depending on who is opening/closing the door.
    Is there another class that I can use?
  2. I'm sorry, what are you trying to do and what part of it isn't working? What is the Value in your hashmap?

    I understand you're trying to get the hashcode, but why?
  3. What makes you think the hashcode is different? I'm willing to bet you're misinterpreting something else e.g. map operations.

    Post your code.
  4. I have a map of Door,UUID for players to be able to lock the doors and prevent others from opening it.
    For debugging purposes, I broadcast the hashcode of the door taken from the map when a person interacts with the door.
    The hashcode is different for each player.
  5. Doors are not a valid key for hash structures, since their hash code changes depending on whether it's open or closed.

    They do not depend on the player in any way, as seen by it's implementation in MaterialData (Door doesn't override it)
  6. Code (Text):
        public void onItemClick(PlayerInteractEvent e) {
            Block clickedBlock = e.getClickedBlock();
            if (clickedBlock != null && clickedBlock.getState() != null && clickedBlock.getState().getData() != null
                    && clickedBlock.getState().getData() instanceof Door) {
                Door door = (Door) clickedBlock.getState().getData();
                Bukkit.broadcastMessage(door.hashCode() + "");
                if (!McRP.mcrp.worldManager.unbuyableDoors.contains(door)) {
                    UUID belongsTo = McRP.mcrp.worldManager.belongings.get(door);
                    if (belongsTo != null && belongsTo != e.getPlayer().getUniqueId()) {
                        String formatted = McRP.format(McRP.mcrp.getConfig().getString("door-claimed"),
                                kv("BELONGS_TO", Bukkit.getPlayer(belongsTo).getName()));
                        McRP.mcrp.notManager.notify(e.getPlayer(), formatted);
  7. So what else can I use?
  8. blocks as vectors?
  9. How would that work, since doors are 2 blocks tall?
  10. Why are you mapping the door state to something in the first place?

    You should be keeping track of the location itself if you're going for this design. You can just reserve two spaces.
    • Informative Informative x 1