Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
- major: Fix targets position in compass when several targets are active
- minor: Fix the way tracker settings are copied, now when a new version is used
  and there are new parameters, they will be added in existing settings files.
- minor: Filter trackers in book interface before render pages
  • Loading branch information
arboriginal committed Feb 13, 2019
1 parent b184b10 commit 1fd37d8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
11 changes: 7 additions & 4 deletions src/me/arboriginal/SimpleCompass/commands/InterfaceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ private void buildInterfaceOptions(
}

private void buildInterfaceTracking(Player player, BookMeta meta) {
Set<String> ordered = sc.locale
.getConfigurationSection("commands." + mainCommand + ".track.buttons").getKeys(false);
List<String> trackers = new ArrayList<String>();
Set<String> ordered = sc.locale.getConfigurationSection(
"commands." + mainCommand + ".track.buttons").getKeys(false);

for (String[] part : chunk(sc.targets.trackersPriority,
for (String trackerID : sc.targets.trackersPriority)
if (player.hasPermission("scompass.track." + trackerID)) trackers.add(trackerID);

for (String[] part : chunk(trackers.toArray(new String[trackers.size()]),
sc.locale.getInt("commands." + mainCommand + ".track.per_page"))) {
ArrayList<BaseComponent> content = new ArrayList<BaseComponent>();
content.add(new TextComponent(sc.prepareMessage("commands." + mainCommand + ".header") + "\n\n"));

for (String trackerID : part) {
if (!player.hasPermission("scompass.track." + trackerID)) continue;
AbstractTracker tracker = sc.trackers.get(trackerID);
if (tracker == null) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ private String injectActivatedTrackers(String compass, String sepColor) {
if (targets.isEmpty()) return compass;

Location refPos = owner.getEyeLocation();
Vector lookAt = refPos.getDirection().setY(0);

HashMap<String, String> placeholders = new HashMap<String, String>();

Expand All @@ -155,10 +154,11 @@ private String injectActivatedTrackers(String compass, String sepColor) {
String symbol = tracker.settings.getString("settings.symbol");
placeholders.put(marker, symbol + sepColor);

for (double[] target : targets.get(type)) {
for (double[] target : coords) {
Vector blockDirection = new Location(owner.getWorld(), target[0], refPos.getY(), target[1])
.subtract(refPos).toVector().normalize();

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;
Expand Down
38 changes: 25 additions & 13 deletions src/me/arboriginal/SimpleCompass/plugin/AbstractTracker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.arboriginal.SimpleCompass.plugin;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -14,7 +16,6 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import com.google.common.collect.ImmutableMap;
import me.arboriginal.SimpleCompass.utils.LangUtil;

public abstract class AbstractTracker {
protected SimpleCompass sc;
Expand Down Expand Up @@ -66,21 +67,32 @@ public String version() {
* so DO NOT USE sc.config here, and DO NOT call methods which use this.
*/
public boolean init() {
if (!sf.exists()) {
URL res = getClass().getResource("/settings.yml");
if (res == null) return false;
URL res = getClass().getResource("/settings.yml");
if (res == null) return false;

try {
LangUtil.writeResourceToFile(res.openStream(), sf);
sc.getLogger().info("Default settings for " + trackerID() + " tracker copied into " + sf.getPath());
}
catch (Exception e) {
sc.getLogger().severe("Can't write to " + sf.getAbsolutePath());
return false;
}
settings = YamlConfiguration.loadConfiguration(sf);
settings.options().copyDefaults(true);

InputStream is;

try {
is = res.openStream();
}
catch (Exception e) {
sc.getLogger().warning("Can't write default settings to " + sf.getAbsolutePath());
return false;
}

settings.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(is)));

try {
settings.save(sf);
}
catch (Exception e) {
sc.getLogger().severe("Can't write to " + sf.getAbsolutePath());
return false;
}

settings = YamlConfiguration.loadConfiguration(sf);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/me/arboriginal/SimpleCompass/plugin/SimpleCompass.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private Exception loadTrackerFile(File file) {
catch (Exception e) {}

if (entries == null)
return loadTrackerException(loader, jar, "Can't initialize a class loader from " + file.getName());
return loadTrackerException(loader, jar, "Can't read content of " + file.getName());

while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
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.3
version: 0.9.4

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

0 comments on commit 1fd37d8

Please sign in to comment.