Location/Config issues?

Discussion in 'Plugin Development' started by Developher, Aug 1, 2012.

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

    Developher

    I am making a plugin where when a player enters a portal (only on a specified [configured] location, they are to do a command). I have made everything, but it doesn't seem to work.

    Code:
    package me.developher.meepportals;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerPortalEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class MeepPortals extends JavaPlugin implements Listener{
     
    @Override
    public void onEnable() {
     
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveConfig();
     
    }
     
    @Override
    public void onDisable() {
     
    }
     
    @EventHandler
    public void PlayerEnterPortalEvent(PlayerPortalEvent e) {
     
    World world = (World) (((Player) e.getPlayer()).getWorld());
    Location loc1 = new Location(world, getConfig().getInt("COORDS1"), getConfig().getInt("COORDS2"), getConfig().getInt("COORDS3"));
    Location loc2 = new Location(world, getConfig().getInt("2COORDS1"), getConfig().getInt("2COORDS2"), getConfig().getInt("2COORDS3"));
     
    if(e.getPlayer().getLocation().equals(loc1) || e.getPlayer().getLocation().equals(loc2)) {
     
    e.getPlayer().sendMessage(ChatColor.GREEN + "[" + ChatColor.DARK_GREEN + "MeepPortals" + ChatColor.GREEN + "] You have been teleported!");
    e.getPlayer().performCommand("wilderness");
     
    }
     
    if(!e.getPlayer().getLocation().equals(loc1) || e.getPlayer().getLocation().equals(loc2)) {
    return;
    }
    }
    }
    
    Here is the config.

    Code:
     
    # MeepPortals v0.1 by Developher. MeepCraft 2012. 
    COORDS1: 57
    COORDS2: 66
    COORDS3: 180
    2COORDS1: 56
    2COORDS2: 66
    2COORDS3: 180
    
    I place in the config the location of the 2 bottom obsidian in a portal, (where players stand and the event occurs).

    Bump.

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

    raGan.

    Maybe because coordinates are stored in double, so you are not standing "exactly" where you should.
    Try e.getPlayer().getLocation().distance(loc1) < 1 || e.getPlayer().getLocation().distance(loc2) < 1.
     
  3. Offline

    pzxc

    He's right, not a good idea to do .equals on a Location

    Also you get bonus points if you use distanceSquared() < 1 instead of distance()... it doesn't need to take a square root so it's slightly faster :)
     
  4. Offline

    Developher

    Thank you both!
     
  5. Offline

    Malikk

    I would think a simple getLocation().getBlock().getLocation would fix this, rather than checking distance.
     
Thread Status:
Not open for further replies.

Share This Page