1.18.2 Check When Custom Tripwire Hook is Triggered

Discussion in 'Spigot Plugin Development' started by ShyneeYT, May 14, 2022.

  1. Hi! I have set up my plugin so that players can use a command to give themselves custom tripwire hooks that have a custom lore. Then, I want to check when a player activates these specific tripwires. The issue is that when a tripwire hook is made into a tripwire, it resets the lore and name of the hooks. Is there any way around this or a better way to do it? Thanks! Here is how I currently am checking:
    Code (Java):
    @EventHandler
        public void tripwireEvent(PlayerInteractEvent e){
            if (playersInJungle.contains(e.getPlayer()) && e.getAction() == Action.PHYSICAL && e.getItem().getItemMeta().getLore().contains("Tripwire that sends messages to Discord")){
                String message = config.getString("TripWireMessage").replaceAll("<PlayerName>", e.getPlayer().getDisplayName());
                broadcast(message);
            }
     
  2. Perhaps you could save the block position of all placed (custom) tripwires together with the text that you want to display when a specific tripwire is hit.

    In your PlayerInteractEvent take the block position from the players feet and retrieve the custom message.
     
  3. there should be a Tripwire and a TripwireHook object, you could listen to PlayerMoveEvent ( ofc make good checks to see if the player has walked since this method is pretty heavy since it can trigget up to 16 times per tick ( PER PLAYER )) then you can check where the player is standing if it's a tripwire just get the Tripwire object and check if it is activated