1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!


    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Type casting in skript-mirror?

Discussion in 'Skript' started by Xander402, Nov 8, 2020.

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

    Xander402 Member

    Aug 20, 2019
    Likes Received:
    Hello, everyone
    I want to destroy (so that it will drop itself and its contents) a minecart with hopper that got under a certain chest.
    My code I wrote so far (I'm using the skript-mirror add-on):
    Code (Text):
    1. import:
    2.     org.bukkit.event.inventory.InventoryMoveItemEvent
    3.     org.bukkit.event.inventory.InventoryType
    4. on InventoryMoveItemEvent:
    5.     if event.getDestination().getType() is InventoryType.HOPPER:
    6.         ...
    7.         set {_minecart} to event.getDestination().getHolder()
    8.         send "%{_minecart}'s location%" to all players
    9.         {_minecart}.setDamage(50)
    only shows the minecart's position (which at least is the sign proving that most of the code works properly) and I know exactly why this happens (or at least I think I do).
    The local variable {_minecart} is an instance of org.bukkit.inventory.InventoryHolder, which inherits the getLocation() method from org.bukkit.entity.Entity.
    In order to call the setDamage(int) method on that variable, it should be cast to org.bukkit.entity.minecart.HopperMinecart or org.bukkit.entity.Minecart. And this is my question. How can I cast {_minecart} to one of the above-mentioned interfaces? Skript does not recognize either the standard Java way of doing it or the Skipt native parsed as expression. Any ideas?
Thread Status:
Not open for further replies.

Share This Page