Skip to content

Commit 1fd37d8

Browse files
author
arboriginal
committed
Bugfixes
- 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
1 parent b184b10 commit 1fd37d8

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

src/me/arboriginal/SimpleCompass/commands/InterfaceCommand.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,19 @@ private void buildInterfaceOptions(
149149
}
150150

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

155-
for (String[] part : chunk(sc.targets.trackersPriority,
156+
for (String trackerID : sc.targets.trackersPriority)
157+
if (player.hasPermission("scompass.track." + trackerID)) trackers.add(trackerID);
158+
159+
for (String[] part : chunk(trackers.toArray(new String[trackers.size()]),
156160
sc.locale.getInt("commands." + mainCommand + ".track.per_page"))) {
157161
ArrayList<BaseComponent> content = new ArrayList<BaseComponent>();
158162
content.add(new TextComponent(sc.prepareMessage("commands." + mainCommand + ".header") + "\n\n"));
159163

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

src/me/arboriginal/SimpleCompass/compasses/AbstractCompass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ private String injectActivatedTrackers(String compass, String sepColor) {
142142
if (targets.isEmpty()) return compass;
143143

144144
Location refPos = owner.getEyeLocation();
145-
Vector lookAt = refPos.getDirection().setY(0);
146145

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

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

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

161+
Vector lookAt = refPos.getDirection().setY(0);
162162
boolean viewable = (lookAt.dot(blockDirection) > 0);
163163
double angle = Math.toDegrees(blockDirection.angle(lookAt.crossProduct(new Vector(0, 1, 0))));
164164
if (!viewable) angle = (angle > 90) ? 180 : 0;

src/me/arboriginal/SimpleCompass/plugin/AbstractTracker.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package me.arboriginal.SimpleCompass.plugin;
22

33
import java.io.File;
4+
import java.io.InputStream;
5+
import java.io.InputStreamReader;
46
import java.net.URL;
57
import java.util.ArrayList;
68
import java.util.HashMap;
@@ -14,7 +16,6 @@
1416
import org.bukkit.configuration.file.YamlConfiguration;
1517
import org.bukkit.entity.Player;
1618
import com.google.common.collect.ImmutableMap;
17-
import me.arboriginal.SimpleCompass.utils.LangUtil;
1819

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

73-
try {
74-
LangUtil.writeResourceToFile(res.openStream(), sf);
75-
sc.getLogger().info("Default settings for " + trackerID() + " tracker copied into " + sf.getPath());
76-
}
77-
catch (Exception e) {
78-
sc.getLogger().severe("Can't write to " + sf.getAbsolutePath());
79-
return false;
80-
}
73+
settings = YamlConfiguration.loadConfiguration(sf);
74+
settings.options().copyDefaults(true);
75+
76+
InputStream is;
77+
78+
try {
79+
is = res.openStream();
80+
}
81+
catch (Exception e) {
82+
sc.getLogger().warning("Can't write default settings to " + sf.getAbsolutePath());
83+
return false;
84+
}
85+
86+
settings.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(is)));
87+
88+
try {
89+
settings.save(sf);
90+
}
91+
catch (Exception e) {
92+
sc.getLogger().severe("Can't write to " + sf.getAbsolutePath());
93+
return false;
8194
}
8295

83-
settings = YamlConfiguration.loadConfiguration(sf);
8496
return true;
8597
}
8698

src/me/arboriginal/SimpleCompass/plugin/SimpleCompass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private Exception loadTrackerFile(File file) {
336336
catch (Exception e) {}
337337

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

341341
while (entries.hasMoreElements()) {
342342
JarEntry entry = entries.nextElement();

src/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: SimpleCompass
22
description: Simple compass to help player who don't have sense of direction.
3-
version: 0.9.3
3+
version: 0.9.4
44

55
author: arboriginal
66
website: https://www.spigotmc.org/resources/simplecompass.63140/

0 commit comments

Comments
 (0)