Light Weighted Pressure Plate and PlayerInteractEvent

Discussion in 'Plugin Development' started by Zerkala8D, Jan 14, 2025.

  1. Offline

    Zerkala8D

    I'm trying to make an event that tracks pressure plate presses. I'm running into the problem that the light weighted pressure plate turns out to trigger the event infinitely many times. How do I get rid of this?
    Code:
    @EventHandler
        public void on(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            for (Quest quest : qp.getQuester(player.getUniqueId()).getCurrentQuests().keySet()) {
    
                if (event.getAction() != Action.PHYSICAL) {
                    return;
                }
    
                if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.STONE_PRESSURE_PLATE || event.getClickedBlock().getType() == Material.LIGHT_WEIGHTED_PRESSURE_PLATE || event.getClickedBlock().getType() == Material.HEAVY_WEIGHTED_PRESSURE_PLATE) {
                    incrementObjective(player.getUniqueId(), this, quest, 1);
                }
            }
        }
     
  2. Online

    timtower Administrator Administrator Moderator

    @Zerkala8D Keep track of the last pressure plate that is pressed per player?
     
  3. Offline

    Zerkala8D

    @timtower It's not really a plugin, but an add-on to the Quests plugin
     
  4. Online

    timtower Administrator Administrator Moderator

    And how exactly does that invalidate my statement?
     
  5. Offline

    Zerkala8D

    @timtower I don't speak English very well and i dont know what you mean..:(
     
  6. Online

    timtower Administrator Administrator Moderator

    Plugin or not, method still fits your usecase.
     
  7. Offline

    Zerkala8D

    @timtower Im about keeping track of the last pressure plate that is pressed per player
     
  8. Online

    timtower Administrator Administrator Moderator

    Store what pressure plate is last pressed, if it is the same: don't increment
     
  9. Offline

    Zerkala8D

    @timtower I dont need this. Just the opposite

    I need the quest to be credited even if the player jumped on the same plate, and when the player stands on the Light Weighted Pressure Plate, the points on the quest are credited indefinitely

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 14, 2025
  10. Online

    timtower Administrator Administrator Moderator

    @Zerkala8D Then you need a timed task to check if they are on a plate
     

Share This Page