Solved Piston Event

Discussion in 'Spigot Plugin Development' started by flyvendetorsk, Jun 8, 2016.

  1. The BlockPistonRetractEvent does not return any player, and i understand that. But is it possible to get the person who activates the piston etc? I could not find any event that could trigger this.
  2. PlayerInteractEvent most likely will be your friend here. Just check the location and the material type to be extra secure!
  3. Try the PlayerInteractEvent, have it test if the player interacts with a lever or button, if so, test if there is a piston within a certain radius of the player, and make sure the Piston retracted. I think that's your best bet.
  4. In short no as for it to be reliable redstone state would have to contain this data.

    The question is why do you want to know?
  5. There is no real reliable way to do this. The only thing I can think of is to listen to the PlayerInteractEvent and tracing any redstone circuits a player may interact with. This would be rather complex, though, as circuits can get rather complex. Think of the game MouseTrap. The redstone circuit could be any length (hundreds or even thousands of blocks long if you were to stretch it out in a line) with any number of things in between, including other pistons.. ;)

    Instead of concentrating on the piston aspect, lets focus on the goal. What is your ultimate goal here? There may be a better way (see XY Problem).
    • Agree Agree x 1
  6. No need to trace redstone circuits. They need to find if the player interacted with the level/button/power source to enable the piston.
    • Optimistic Optimistic x 1
  7. Oh, its that simple huh?

    What if I put a lever 100 blocks away from the piston and connect it with redstone and repeaters? Or maybe I put a button on a tflipflop to control that piston. Or what if I use that WirelessRedstone plugin to connect a lever to my piston remotely?

    How do you know what lever/button controls the piston without tracing the circuit? ;)
  8. @BillyGalbreath You set the location of the lever that powers it. That simple. :p You literally don't need to trace the signal, just get the piston that is powered when the event is fired for security and check the location of the power source. It's best you don't suggest over-complications. :confused:
    • Optimistic Optimistic x 2
  9. That will only work for a special use-case which was not mentioned in the OP. You cant assume the lever is a known variable at all here unless it was specified in the question as being so. This type of question comes up a lot, and 99.9% of the time the power source is never a known variable and could be anything at any location.
    • Agree Agree x 2
  10. @BillyGalbreath Incorrect. I think you're misunderstanding the concept. The player can choose which power sources they want to be stored in the config. All you have to do is check if at the location stored, a power source is activated. The player should know whether or not there is a piston there. Pistons can only be placed by players or the plugin itself.

    There's one of two options here:

    Place the power source via the plugin and map out your own signal to power the piston.


    Write a command to store the location of the power source when you stand over it (players location) or just the nearest entity of power source type.

    Either way, store the location of the power source using your command or whatever you develop.

    After you've done one of the two, when the PlayerInteractEvent fires check if the given power source location interacted with is in the config.
    • Funny Funny x 1
  11. @SwiftLee I'm still missing the bit in the _original post_ which states they know/control the location of the level which should power the piston.
  12. @basicmark that's the point of setting the location. Understand the concept before you try and rebut my method.
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  13. Listen. We know what you are saying. And yes, we agree that it works for a KNOWN power source. But the OP does not know the power source, nor does he want it to be a requirement to know the power source... Until the OP states he wants to link a predetermined power source to the piston your answer is completely incorrect.
    • Agree Agree x 1
  14. I understand your proposed solution perfectly, what I say to you is understand the question before insisting on a solution which doesn't work in the general case.
  15. @BillyGalbreath
    Sorry for not responding, my XY problem is I want to make sure pistons don't move blocks they don't own via a block protection system. Where a player owns a block and let's say in this case the block was a gold block, and then the "griefer" could use a piston to retract the block out of protection, and break it. So that's why I want to get the player who activates the piston, so I can cancel if he doesn't own the block the piston is retracting or pushing.

    EDIT: I fixed it by checking if the piston block owner was equal to the moving block owner. Works like a charm.
    #15 flyvendetorsk, Jun 9, 2016
    Last edited: Jun 9, 2016
  16. Ah yes. I had a similar scenario on my protections plugin. The way I solved it was I didnt let pistons push/pull blocks between protection borders, even if the person doing the action owned both sides of the protection border. ^_^

  17. Okay then buddy, you know it all, just trying to help! :D

    By the way, the power source is defined when they find it. How can you have an UNDEFINED power source! The player or the plugin has to place it!
    • Optimistic Optimistic x 1