1.15.2 mark a location on cutom bossbar compass

Discussion in 'Spigot Plugin Development' started by Scofield__, Mar 18, 2020.

  1. Hey guys.

    I'm working on a bossbar compass, and i would like to mark a locations direction on the compass.
    So if the player facing to the given location, i want to mark that with a red dot or something on the compass.
    Here is my code so far.


    Code (Text):
    Map<UUID, BossBar> bars = new HashMap<>();
       
        @EventHandler
        public void on(PlayerMoveEvent e) {
            Player player = e.getPlayer();
            if (Math.abs(e.getFrom().getYaw() - e.getTo().getYaw()) < 0.2) { return; }

            BossBar bar = bars.get(player.getUniqueId());
            if (bar == null) {
                bar = Bukkit.createBossBar("", BarColor.BLUE, BarStyle.SEGMENTED_20);
                bar.addPlayer(player);
                bars.put(player.getUniqueId(), bar);
            }

            String s = ChatColor.AQUA + "";
            for (int i = (int) Math.abs(player.getLocation().getYaw()) - 16; i < ((int) Math.abs(player.getLocation().getYaw())) + 16; i++) {
                if (i == 0) {
                    s += "D";
                } else if (i == 45) {
                    s += "DNY";
                } else if (i == 90) {
                    s += "NY";
                } else if (i == 135) {
                    s += "ÉNY";
                } else if (i == 180) {
                    s += "É";
                } else if (i == 225) {
                    s += "ÉK";
                } else if (i == 270) {
                    s += "K";
                } else if (i == 315) {
                    s += "DK";
                } else {
                    if (i % 2 == 0) { s += "."; }
                }
                s += " ";
            }

            bar.setTitle(s);
            bar.setVisible(true);
        }
    Thanks.
     
  2. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter


    Well I really love that idea, but is it even possible? I'm quite sure you can just fill the bar to a certain percentage no?
     
  3. Choco

    Moderator

    You cannot. Boss bars can only have one colour.
     
  4. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    What you could do is make the boss bar progress towards the 100% the more you look towards the mob. That sounds pretty nice actually
     
  5. Yes, thats the plan, but i can't figured it out how can i get the certain percentage.
     
  6. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    I'm far from a Math person. But I believe you will need to take the direction of the player, and then compare it with the coords of the entity you want to target.
     
  7. No. Guys. Sorry for misunderstood. My code so far looks like as on the video below. I would like to mark in the name of the boss bar.
    https://streamable.com/s9lof
     
  8. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    Well for me as a non mathical person, that looks great already. But so what exactly are you trying then? Sorry for all the questions
     
  9. For example i have a location on the map, and i want to mark that location on the bossbar. Like in pubg. :D
    So the player will know what direction should to go for.
     
  10. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    I just asked my math friend @pandacrafter1 , you can create a vector based on your location and your mob. if either x or z axis of your vector is equal to 0, you are directly facing the mob