Solved Setting Direction

Discussion in 'Spigot Plugin Development' started by AllinoneGamer, May 14, 2017.

  1. Making a SUMO plugin, and when i teleport them to the platform they face away from each other and i want them facing at each other, they both face the same direction: http://prntscr.com/f7t5kj , for setting the direction i
    did this:

    When i set the location with: /setsumo <1/2>, i stored the direction i was facing in a Vector variable and then set it in the config:
    SetSumo Class:

    Code (Text):

      @Override
       public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
         if(cmd.getName().equalsIgnoreCase("setsumo") && sender instanceof Player) {
           Player p = (Player)sender;
           if(p.hasPermission("admin.setsumo")) {
           if(!(args.length > 0)) {
             p.sendMessage(ChatColor.RED + "Usage: /setsumo <1/2>");
           } else {
             if(args[0].equalsIgnoreCase("1")) {
               
               int x = p.getLocation().getBlockX();
               int y = p.getLocation().getBlockY();
               int z = p.getLocation().getBlockZ();
               Vector vec = p.getLocation().getDirection();
               
               plugin.getConfig().set("Sumo", "");
               plugin.getConfig().set("Sumo" + ".1", "");
               plugin.getConfig().set("Sumo" + ".1" + ".x", x);
               plugin.getConfig().set("Sumo" + ".1" + ".y", y);
               plugin.getConfig().set("Sumo" + ".1" + ".z", z);
               plugin.getConfig().set("Sumo" + ".1" + ".v", vec);
               plugin.saveConfig();
               
               p.sendMessage(ChatColor.AQUA + "Set Sumo1 to: " + ChatColor.GOLD + x + "," + y + "," + z);
             } else if(args[0].equalsIgnoreCase("2")) {
               if(plugin.getConfig().contains("Sumo" + ".1")) {
               int x = p.getLocation().getBlockX();
               int y = p.getLocation().getBlockY();
               int z = p.getLocation().getBlockZ();
               Vector vec = p.getLocation().getDirection();
               
               plugin.getConfig().set("Sumo" + ".2", "");
               plugin.getConfig().set("Sumo" + ".2" + ".x", x);
               plugin.getConfig().set("Sumo" + ".2" + ".y", y);
               plugin.getConfig().set("Sumo" + ".2" + ".z", z);
               plugin.getConfig().set("Sumo" + ".2" + ".v", vec);
               plugin.saveConfig();
               p.sendMessage(ChatColor.AQUA + "Set Sumo2 to: " + ChatColor.GOLD + x + "," + y + "," + z);
             } else {
               p.sendMessage(ChatColor.RED + "You need to set Sumo1 first!");
             }
             }
           }
           }
         }
         return false;
       }

    }
     
    Config:

    Code (Text):

    Sumo:
      '1':
      x: 12
      y: 45
      z: -41
      v:
      ==: Vector
      x: -0.9996884228265279
      y: 0.008152529781567611
      z: -0.02359223441664226
      '2':
      x: 8
      y: 45
      z: -41
      v:
      ==: Vector
      x: 0.9926328798497831
      y: -0.11851388815171503
      z: 0.025187777914870174
    Lobby:
      x: 13
      y: 41
      z: -21
    SumoLobby:
      x: 0
      y: 45
      z: -40
     
    And when setting direction:
    Code (Text):

    int x1 = plugin.getConfig().getInt("Sumo" + ".1" + ".x");
           int y1 = plugin.getConfig().getInt("Sumo" + ".1" + ".y");
           int z1 = plugin.getConfig().getInt("Sumo" + ".1" + ".z");
           Vector vec1 = plugin.getConfig().getVector("Sumo" + ".1" + ".v");
           
           Location loc1 = new Location(p1.getWorld(),x1,y1,z1);
           
           int x2 = plugin.getConfig().getInt("Sumo" + ".2" + ".x");
           int y2 = plugin.getConfig().getInt("Sumo" + ".2" + ".y");
           int z2 = plugin.getConfig().getInt("Sumo" + ".2" + ".z");
           Vector vec2 = plugin.getConfig().getVector("Sumo" + ".2" + ".v");
           
           Location loc2 = new Location(p1.getWorld(),x2,y2,z2);
           
           p1.getLocation().setDirection(vec1);
           p1.teleport(loc1);
           p2.getLocation().setDirection(vec2);
           p2.teleport(loc2);
           
           
           
       }
     
     
  2. BananaPuncher714

    Supporter

    Try setting their direction AFTER teleporting them.
     
  3. Well, you use #setDirection on the Location object, so you'd want to set the direction of the location object you use for #teleport.

    I'd just get the vector difference of the two points:

    Code (Java):
    Location one = /* first point */;
    Location two = /* second point */;
    Vector diff = two.toVector().subtract(one.toVector());
    one.setDirection(diff);
    two.setDirection(diff.multiply(-1)); //reverse the direction vector
    //teleport
     
  4. Thank's that worked.