Portal Types : How to detect them?

Discussion in 'Plugin Development' started by pookeythekid, Feb 14, 2014.

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

    pookeythekid

    Hello. I'm here asking about portal types. I'm making my own plugin to solve my issue that on my server, my 1.6.4 world has its own Nether and End worlds, but the 1.7.2 world will not generate its own Nether and End worlds; in fact, I've found a stronghold in the 1.7.2 world that doesn't even have an End portal. I hope someone has the answer to this so I can proceed with my development. Thanks! :)
    I have little code written already, as I just started today and encountered this problem. If it helps, here's what I have in my first portal listener class so far.

    Code:java
    1. package me.pookeythekid.Portals.Listeners;
    2.  
    3. import me.pookeythekid.Portals.Main;
    4.  
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerPortalEvent;
    8.  
    9. public class NetherPortals implements Listener {
    10.  
    11. public Main M;
    12.  
    13. public NetherPortals(Main instance) {
    14. M = instance;
    15. }
    16.  
    17. @EventHandler
    18. public void onNetherPortalEnter(PlayerPortalEvent e) {
    19.  
    20. }
    21.  
    22. }
     
  2. Offline

    xTrollxDudex

    pookeythekid
    Check if the getCause() equals a PlayerTeleportEvent.TeleportCause NETHER or END portals
     
  3. Offline

    pookeythekid

    xTrollxDudex Ah thanks! I was using "PlayerPortalEvent"!!! That must be why I didn't see "e.getCause()" in my list of options (I use Eclipse Kepler). Thanks for clarifying. :D

    xTrollxDudex Hm. I tried these two pieces of code and it didn't work.
    Code:java
    1. @EventHandler
    2. public void onPlayerPortal(PlayerTeleportEvent e) {
    3. if (e.getCause() == PortalType.NETHER /*or ENDER*/) {
    4. //code
    5. }
    6. }

    Code:java
    1. @EventHandler
    2. public void onPlayerPortal(PlayerTeleportEvent e) {
    3. if (e.getCause() instanceof PortalType.NETHER /*or ENDER*/) {
    4. //code
    5. }
    6. }


    xTrollxDudex Oh! Nevermind, it works! :D
    Code:java
    1. e.getCause().NETHER_PORTAL
    2. //or
    3. e.getCause().ENDER_PORTAL


    Edit: Okay, this is a little odd and lame at the same time. :/
    Code:java
    1. if (e.getCause() == TeleportCause.NETHER_PORTAL) {
    2. //code
    3. }


    It corrected me to this, but when I originally used it, it didn't work! >: (

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  4. Offline

    MrAwellstein

    This may be old (idk I'm on my phone) but is there anyway to check the type of portal before they teleport? I was thinking possibly check the nearest blocks but that may slow down the plugin.

    Edit:
    Forgot my portals don't work anyways, so I can't use the teleport event.
     
  5. Offline

    Garris0n

    With the teleport event...
     
  6. Offline

    MrAwellstein

    Isn't that only called when a player teleports
     
  7. Offline

    Garris0n

    If an event is cancellable that almost always means it's called right before the thing happens so you can stop it. One known exception to this is the PlayerDropItemEvent, which leads to that dreadful error where the item moves to a different slot in the player's inventory.
     
  8. Offline

    MrAwellstein

    I don't think I'm understanding you correctly. Are you saying that the event, player teleport event, will run when the player wasn't teleported? Well, I'll try it but I'm pretty sure it wont work xD
     
  9. Offline

    Garris0n

    Yes. Not teleported yet.
     
  10. Offline

    MrAwellstein

    It didn't work, but the event was being fired (just not when I entered the portal). I got the chance to see that PlayerPortalEvent has a getCause() method though.. And honestly I swear that wasnt there before xD
    Thanks for your help anyways, Garris0n ^_^
     
  11. Offline

    pookeythekid

    I've tried using PlayerPortalEvent, testing the event by sending the player a message when they used the portal. It didn't work... Any idea what you did differently? Here's the code I used.

    Code:java
    1. package me.pookeythekid.Portals.Listeners;
    2.  
    3. import me.pookeythekid.Portals.Main;
    4.  
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerPortalEvent;
    8.  
    9. public class NetherPortals implements Listener {
    10.  
    11. public Main M;
    12.  
    13. public NetherPortals(Main instance) {
    14. M = instance;
    15. }
    16.  
    17. @EventHandler
    18. public void onPortalEnter(PlayerPortalEvent e) {
    19. e.getPlayer().sendMessage("HELLO");
    20. }
    21.  
    22. }
     
  12. Offline

    Drew1080

    pookeythekid
    Did you register the event in your main class?
     
  13. Offline

    pookeythekid

    Drew1080 I'm quite sure I did. Let me check. I'm pretty sure it would give me a "Can't pass event" error if I didn't.

    Edit: Yeah, I registered the events.
    Code:java
    1. package me.pookeythekid.Portals;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.plugin.PluginDescriptionFile;
    6. import org.bukkit.plugin.PluginManager;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. import me.pookeythekid.Portals.Listeners.NetherPortals;
    10.  
    11. public class Main extends JavaPlugin {
    12.  
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14. public final PluginDescriptionFile pdf = this.getDescription();
    15. public final PluginManager pm = this.getServer().getPluginManager();
    16. public final NetherPortals np = new NetherPortals(this);
    17.  
    18. @Override
    19. public void onDisable() {
    20. logger.info("[" + pdf.getName() + "] Portals v" + pdf.getVersion() + " Is Now Enabled.");
    21. }
    22.  
    23. @Override
    24. public void onEnable() {
    25. logger.info("[" + pdf.getName() + "] Portals Is Now Disabled.");
    26.  
    27. pm.registerEvents(np, this);
    28. }
    29.  
    30. }
    31.  
     
  14. Offline

    MrAwellstein

    Code:java
    1. @EventHandler
    2. public void portalEvent(PlayerPortalEvent event){
    3. event.getPlayer().sendMessage(event.getCause().toString());
    4. event.getPlayer().sendMessage("Entering From "+event.getFrom().getWorld().getName().toString());
    5. }

    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(new Listeners(), this);

    [​IMG]
    [​IMG]
     
  15. Offline

    pookeythekid

    MrAwellstein So.... it's "playerPortal(blah event name)" instead of "onPlayerPortal"? Or does it matter?

    Edit: Also, does "toString()" mean to make an object a string? And if so, then do you need to send the player "getWorld().getName().toString()"? I'm pretty sure "getName()" is already a string by itself.
     
  16. Offline

    MrAwellstein


    I just get OCD about the .getName(). I dont have to do .toString()
    Also I dont think your listener is being called.
     
  17. Offline

    pookeythekid

    MrAwellstein Sorry for the late reply. School started again. -_- I had a week off last week. Why don't you think my listener is being called?
     
  18. Offline

    MrAwellstein

    It just doesn't look like it's being registered. And it's fine, it was the same for me (the school thing)
     
  19. Offline

    pookeythekid

    MrAwellstein The way I'm using my listener is the same way I'm doing it with my plugin SecureLogin. You can see it if you click the My Plugins link in my profile summary to the left. SecureLogin is functional with its listeners, and having done just the same in this portals plugin, I don't see why the listener isn't being called. My listener registering is in my main class in the first post of this message, if you want to look at that to see what I'm doing wrong.
     
  20. Offline

    MrAwellstein

    Try doing thep = new NetherPortals(this); in the on enable, rather than just being there not in a method

    Alsop
    m.registerEvents(new NetherPortal(this), this);
    Will work.

    In case you don't know, player portal event only is called when the attempted teleportation happens. Meaning if you are expecting it to happen when you walk into the portal it won't be called instantly unless you are in creative

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  21. Offline

    pookeythekid

    MrAwellstein Creative.... I think I've been in Creative every time I went through the portal... But I do think it's interesting how it only gets called instantly if you're in Creative Mode. I wonder if that's fixable, or if the Bukkit Dev team is already on it. Anyway, thanks, I'll try it in Survival Mode now and see if the listener works.
     
  22. Offline

    MrAwellstein

    Its fixable with packets.
     
  23. Offline

    pookeythekid

    MrAwellstein Ew, packets. Something I will never understand... xD
    By the way, it didn't end up working in Survival. At least not with my method of listeners. But oh well, I found a better way to handle the problem on my server anyway.
     
  24. Offline

    MrAwellstein


    Thats good :D
     
  25. Offline

    pookeythekid

    MrAwellstein Even though I've found a solution anyway... I have discovered something new. In my server console on the startup, it says the plugin simply can't load. "Could not load file "plugins/Portals.jar"" or whatever.

    MrAwellstein I also know that my listeners work because I'm making another plugin that uses listeners with the same method and it works.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page