Skip to content

Commit

Permalink
Add highlight target ability
Browse files Browse the repository at this point in the history
  • Loading branch information
arboriginal committed Feb 22, 2019
1 parent 51bc439 commit c5d9775
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can download the last release here: [SimpleCompass.jar](https://github.com/a

## Permissions

All permissions are listed with a short description in this [plugin.yml](https://github.com/arboriginal/SimpleCompass/blob/master/src/plugin.yml).
All permissions are listed with a short description in this [plugin.yml](https://github.com/arboriginal/SimpleCompass/blob/master/src/plugin.yml#L41).

## Commands

Expand Down
28 changes: 20 additions & 8 deletions src/me/arboriginal/SimpleCompass/compasses/AbstractCompass.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,22 @@ private String injectActivatedTrackers(String compass, String sepColor) {
for (String trackerID : sc.targets.trackersPriority) {
AbstractTracker tracker = sc.trackers.get(trackerID);
if (tracker == null) continue;
int hlMaxAngle = tracker.settings.getInt("settings.hl_angle", 0);
String hlMarker = null, hlSymbol = null;

if (hlMaxAngle > 0) {
hlMarker = tracker.settings.getString("settings.hl_temp", null);
hlSymbol = tracker.settings.getString("settings.hl_symbol", null);
if (hlMarker != null && hlSymbol != null) placeholders.put(hlMarker, hlSymbol + sepColor);
}

for (String targetType : targets.keySet()) {
ArrayList<double[]> coords = targets.get(targetType).get(trackerID);
if (coords == null || coords.isEmpty()) continue;
boolean active = targetType.equals("on");

String marker = tracker.settings
.getString("settings." + (targetType.equals("off") ? "inactive_" : "") + "temp");
String symbol = tracker.settings
.getString("settings." + (targetType.equals("off") ? "inactive_" : "") + "symbol");

String marker = tracker.settings.getString("settings." + (active ? "" : "inactive_") + "temp");
String symbol = tracker.settings.getString("settings." + (active ? "" : "inactive_") + "symbol");
placeholders.put(marker, symbol + sepColor);

for (double[] target : coords) {
Expand All @@ -167,11 +173,17 @@ private String injectActivatedTrackers(String compass, String sepColor) {
Vector lookAt = refPos.getDirection().setY(0);
boolean viewable = (lookAt.dot(blockDirection) > 0);
double angle = Math.toDegrees(blockDirection.angle(lookAt.crossProduct(new Vector(0, 1, 0))));
if (!viewable) angle = (angle > 90) ? 180 : 0;
String tMarker = marker;

if (!viewable)
angle = (angle > 90) ? 180 : 0;
else if (active && hlMarker != null && hlSymbol != null && angle > 90 - hlMaxAngle && angle < 90 + hlMaxAngle)
tMarker = hlMarker;

int start = compass.length() - (int) Math.round(2 * angle * compass.length() / 360);

compass = (start < 2) ? marker + compass.substring(start + 1)
: compass.substring(0, start - 1) + marker + compass.substring(start);
compass = (start < 2) ? tMarker + compass.substring(start + 1)
: compass.substring(0, start - 1) + tMarker + compass.substring(start);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SimpleCompass
description: Simple compass to help player who don't have sense of direction.
version: 0.9.8
version: 0.9.9

author: arboriginal
website: https://www.spigotmc.org/resources/simplecompass.63140/
Expand Down

0 comments on commit c5d9775

Please sign in to comment.