Location/Config issues?

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

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


    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.

    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{
    public void onEnable() {
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(this, this);
    public void onDisable() {
    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!");
    if(!e.getPlayer().getLocation().equals(loc1) || e.getPlayer().getLocation().equals(loc2)) {
    Here is the config.

    # 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).


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


    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


    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


    Thank you both!
  5. Offline


    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