Solved Multiverse API - MVPlayerTouchedPortalEvent not triggering.

Discussion in 'Spigot Plugin Development' started by PixelSpree, Apr 17, 2017.

  1. I have this bit of code here:
    Code (Text):
    public class EventManager implements Listener {
        @EventHandler
        public void onPlayerTouchedPortal (MVPlayerTouchedPortalEvent event) {
            Player player = event.getPlayer();
            String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
            player.sendMessage(name);
            if (name.toLowerCase().contains("iron")) {
                player.sendMessage("Cannot hold anything iron when teleporting to another world.");
                event.setCancelled(true);
            }
        }
    }
    Whenever I try to pass through a portal, no message is sent to me even though at least one should be sent, meaning the event doesn't trigger at all. Maybe it has something to do with my dependencies? This is my pom.xml:
    Code (Text):
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                </resource>
            </resources>
        </build>
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>Multiverse-Core</id>
                <url>http://repo.onarandombox.com/content/repositories/multiverse/</url>
            </repository>
            <repository>
                <id>Multiverse-Portals</id>
                <url>http://repo.onarandombox.com/content/repositories/multiverse/</url>
            </repository>
        </repositories>
        <dependencies>
            <!--Spigot API-->
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.11.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <!--Multiverse API-->
            <dependency>
                <groupId>com.onarandombox.multiversecore</groupId>
                <artifactId>Multiverse-Core</artifactId>
                <version>2.5.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.onarandombox.multiverseportals</groupId>
                <artifactId>Multiverse-Portals</artifactId>
                <version>2.5.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
    And I already added both multiverse-core and -portals to my dependencies in Project Structure (in IntelliJ). Am I doing this wrong?
     
  2. You must more information, but doc. plugin is in site developer.
     
  3. I did look at their only wiki at github and the only information there is about the multiverse ingame commands and nothing about their multiverse api.
     
  4. I have finally fixed it!

    The MVPlayerTouchedPortalEvent still doesn't trigger, but there's another event that triggers when you teleport through a portal: MVPortalEvent

    An example code of this in action:
    Code (Text):
    public class EventManager implements Listener {
        @EventHandler
        public void onPortal (MVPortalEvent event) {
            Player player = event.getTeleportee();
            String itemName = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();

            if (itemName.toLowerCase().contains("iron")) {
                player.sendMessage(ChatColor.RED + "Cannot hold anything iron when teleporting to another world.");
                event.setCancelled(true);
                return;
            }

            player.sendMessage("Teleported through portal!");
        }
    }
    Also, a sidenote here is: Cancelling an event through setCancelled is not enough; you gotta return too to fully cancel the event, even if it returns void.

    Edit: You need Multiverse-Portals to use the MVPortalEvent.
     
    #5 PixelSpree, Apr 17, 2017
    Last edited: Apr 17, 2017