Skip to content

Commit 91a2cc7

Browse files
committed
Added offset setting for holograms. #382
1 parent 19179bc commit 91a2cc7

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/main/java/world/bentobox/aoneblock/Settings.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public class Settings implements WorldSettings {
107107
@ConfigEntry(path = "world.holograms")
108108
private boolean useHolograms = true;
109109

110+
@ConfigComment("Hologram position - the offset to the magic block where holograms will appear")
111+
@ConfigEntry(path = "world.hologram-offset")
112+
private String offset = "0.5, 1.1, 0.5";
113+
110114
@ConfigComment("Duration in seconds that phase holograms will exist after being displayed, if used.")
111115
@ConfigComment("If set to 0, then holograms will persist until cleared some other way.")
112116
@ConfigEntry(path = "world.hologram-duration")
@@ -2195,4 +2199,18 @@ public boolean isDisallowTeamMemberIslands() {
21952199
public void setDisallowTeamMemberIslands(boolean disallowTeamMemberIslands) {
21962200
this.disallowTeamMemberIslands = disallowTeamMemberIslands;
21972201
}
2202+
2203+
/**
2204+
* @return the offset
2205+
*/
2206+
public String getOffset() {
2207+
return offset;
2208+
}
2209+
2210+
/**
2211+
* @param offset the offset to set
2212+
*/
2213+
public void setOffset(String offset) {
2214+
this.offset = offset;
2215+
}
21982216
}

src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.bukkit.event.EventHandler;
1414
import org.bukkit.event.EventPriority;
1515
import org.bukkit.event.Listener;
16+
import org.bukkit.util.Vector;
1617
import org.eclipse.jdt.annotation.NonNull;
1718

1819
import world.bentobox.aoneblock.AOneBlock;
@@ -50,7 +51,7 @@ private Optional<TextDisplay> getHologram(Island island) {
5051
}
5152

5253
private TextDisplay createHologram(Island island) {
53-
Location pos = island.getCenter().clone().add(0.5, 1.1, 0.5);
54+
Location pos = island.getCenter().clone().add(parseVector(addon.getSettings().getOffset()));
5455
World world = pos.getWorld();
5556
assert world != null;
5657

@@ -63,6 +64,25 @@ private TextDisplay createHologram(Island island) {
6364
return newDisplay;
6465
}
6566

67+
private static Vector parseVector(String str) {
68+
if (str == null) {
69+
return new Vector(0.5, 1.1, 0.5);
70+
}
71+
String[] parts = str.split(",");
72+
if (parts.length != 3) {
73+
return new Vector(0.5, 1.1, 0.5);
74+
}
75+
76+
try {
77+
double x = Double.parseDouble(parts[0].trim());
78+
double y = Double.parseDouble(parts[1].trim());
79+
double z = Double.parseDouble(parts[2].trim());
80+
return new Vector(x, y, z);
81+
} catch (NumberFormatException e) {
82+
return new Vector(0.5, 1.1, 0.5);
83+
}
84+
}
85+
6686
private void clearIfInitialized(TextDisplay hologram) {
6787
if (hologram.isValid()) {
6888
hologram.remove();

src/main/resources/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ world:
5555
difficulty: NORMAL
5656
# Display holograms
5757
holograms: true
58+
# Hologram position - the offset to the magic block where holograms will appear
59+
hologram-offset: 0.5, 1.1, 0.5
5860
# Duration in seconds that phase holograms will exist after being displayed, if used.
5961
# If set to 0, then holograms will persist until cleared some other way.
6062
hologram-duration: 10
@@ -193,9 +195,9 @@ world:
193195
create-obsidian-platform: false
194196
# Mob white list - these mobs will NOT be removed when logging in or doing /island
195197
remove-mobs-whitelist:
196-
- WITHER
197-
- ZOMBIE_VILLAGER
198198
- ENDERMAN
199+
- ZOMBIE_VILLAGER
200+
- WITHER
199201
# World flags. These are boolean settings for various flags for this world
200202
flags:
201203
CREEPER_DAMAGE: true

0 commit comments

Comments
 (0)