1.14.4 Teleport entity back to location?

Discussion in 'Spigot Plugin Development' started by kinukin, Feb 2, 2020.

  1. So I want to teleport a entity back to its original location but it's mixing up the two different locations?

    I have a function that's the same in different classes but with different locations. But when the entity teleports it sometimes teleport to a different location set.
    I only want the entity to teleport back to the location set, how can I do that without mixing the locations?

    Class 1:
    Code (Text):
    public void teleportBack(Entity entity) {
    Location location = new Location(Bukkit.getWorld("world"), -4.762, 89, -19.306);
    double distance = entity.getLocation().distance(location);
    double angle = Math.random() * 360;
    double radius = Math.random() * 10;
    Location pos = location.add(Math.cos(angle) * radius, 0, Math.sin(angle) * radius).getWorld().getHighestBlockAt(location).getLocation();
    if(goblinUUID.contains(entity.getUniqueId())) {
    if(distance > 20) {
    System.out.println(entity.getUniqueId());
    entity.teleport(pos);
    }    
    }  
    }
           
    Class 2:
    Code (Text):
    public void teleportBack(Entity entity) {
    Location location = new Location(Bukkit.getWorld("world"), -65.217, 85, -49.124);
    double distance = entity.getLocation().distance(location);
    double angle = Math.random() * 360;
    double radius = Math.random() * 10;
    [Location pos = location.add(Math.cos(angle) * radius, 0, Math.sin(angle) * radius).getWorld().getHighestBlockAt(location).getLocation();
    if(goblinUUID.contains(entity.getUniqueId())) {
    if(distance > 20) {
    System.out.println(entity.getUniqueId());
    entity.teleport(pos);
    }
    }    
     
  2. Holdup, why do you have the same public function in two sperate classes anyway? That just seems like it would cause unnecessary headaches.
     
  3. For two different locations.
     
  4. No dude :facepalm:

    Code (Java):
    public static void teleportBack(Entity entity, Location location) {
    double distance = entity.getLocation().distance(location);
    double angle = Math.random() * 360;
    double radius = Math.random() * 10;
    Location pos = location.add(Math.cos(angle) * radius, 0, Math.sin(angle) * radius).getWorld().getHighestBlockAt(location).getLocation();
    if(goblinUUID.contains(entity.getUniqueId())) {
    if(distance > 20) {
    System.out.println(entity.getUniqueId());
    entity.teleport(pos);
    }  
    }
    }
    Then you use class.teleportBack(player, new Location(Bukkit.getWorld("world"), -4.762, 89, -19.306));