Teleport Help Needed

Discussion in 'Plugin Development' started by SystemShocker, Apr 10, 2012.

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

    SystemShocker

    I'm currently trying to make a plugin where if you fall into the void (or your y coordinate < 0), you will get automatically teleported back to the surface at a set location. I came up with a little bit of code that I thought would work, but it doesn't seem to do anything. I tried multiple other approaches to it, and still didn't get any results. I got a little bit frustrated, gave up for a bit, and now I'm here. :)

    Here's the part of the code that checks for their location in the if statement, and then teleports them to the location I've set as the spawn.

    Code:
        @EventHandler
        public boolean onPlayerLocation(PlayerEvent event) {
            Player player = event.getPlayer();
            Location spawn = new Location(player.getWorld(), -1088, 5, -197);
            if (player.getLocation().getY()<0){
                player.teleport(spawn);
                player.sendMessage(ChatColor.ITALIC + "[VoidTP] You fell into the void! Teleported to spawn.");
                return true;
            }
            return false;
        }
    I'm sure there's some embarrassingly obvious error that I'm not able to find. I'm no expert in java (in fact, I practically just started learning). Any help at all is appreciated. Thanks!
     
  2. Offline

    chaseoes

    What isn't working about it? Telling us "it doesn't work!" does not give us enough information to help you.
     
  3. Offline

    dsmyth1915

    I see one mistake
    ChatColor.Italic WTF???
     
  4. Offline

    chaseoes

    That's not a mistake. It makes italic text.
     
  5. Offline

    CorrieKay

    i would suggest restricting this listener to a player move event, instead of a player event. It doesnt need to fire on block breaks, it doesnt need to fire on inventory changes, or chatting, etc. it'll help your plugin run a bit faster.

    also, make sure that the class this is located in implements the Listener interface, and make sure that youre registering the events in your plugin manager.
     
  6. Offline

    dsmyth1915

    Well I'll be damned... Good work I didn't even know that existed! :D
    http://jd.bukkit.org/doxygen/d7/d06/ChatColor_8java.html

    edit1: also you may want to set the respawn location to getRespawnLocation() instead of hard coding it into your plugin. it'll help it be more flexible.
     
  7. Offline

    IcyRelic

    there also ChatColor.BOLD and ChatColor.MAGIC

    Code:
        @EventHandler
        public boolean onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
         
            if (player.getLocation().getBlockY() < 0) {
                Int X = Integer.parseInt(-1088)
                Int Y = Integer.parseInt(5)
                Int Z = Integer.parseInt(-197)
     
                Location spawn = new Location(player.getWorld(), X, Y, Z);
             
                player.teleport(spawn);
                player.sendMessage(ChatColor.ITALIC + "[VoidTP] You fell into the void! Teleported to spawn.");
                return true;
            }
            return true;
        }
    try this im pretty sure its PlayerMove or something close to it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  8. Offline

    SystemShocker

    Thank you! I did everything you said and it works perfectly. Told you it was some stupid mistake like not registering the event...
     
    CorrieKay likes this.
Thread Status:
Not open for further replies.

Share This Page