Ir para conteúdo
  • 0

Objeto em Metodo


ONZE

Pergunta

Como faço para pegar o objeto de um metodo e usar em outro metodo?

 

public void guardar(){
World world = Bukkit.getServer().getWorld(getConfig().getString("Spawn.World"));
Double x = getConfig().getDouble("Spawn.X");
Double y =  getConfig().getDouble("Spawn.Y");
Double z = getConfig().getDouble("Spawn.Z");
Location loc = new Location(world, x, y, z);
loc.setPitch((float) getConfig().getDouble("Spawn.Pitch"));
loc.setYaw((float) getConfig().getDouble("Spawn.Yaw")); 
}


@EventHandler
public void onJoinSpawn(PlayerJoinEvent e){
    Player p = e.getPlayer();
    p.teleport(loc); 
}

 e outra coisa.. seria bom eu verificar no Event se existe um Spawn no config antes de teleportar ?

Editado por ONZE
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0


public class Test implements Listener {

private Location loc;

 

public Test() {

guardar();

}

 

public void guardar(){

World world = Bukkit.getServer().getWorld(getConfig().getString("Spawn.World"));

Double x = getConfig().getDouble("Spawn.X");

Double y = getConfig().getDouble("Spawn.Y");

Double z = getConfig().getDouble("Spawn.Z");

loc = new Location(world, x, y, z);

loc.setPitch((float) getConfig().getDouble("Spawn.Pitch"));

loc.setYaw((float) getConfig().getDouble("Spawn.Yaw"));

}

 

 

@EventHandler

public void onJoinSpawn(PlayerJoinEvent e){

Player p = e.getPlayer();

p.teleport(loc);

}

}

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...