Skip to content

Commit

Permalink
Added offset setting for holograms. #382
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Apr 7, 2024
1 parent 19179bc commit 91a2cc7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.holograms")
private boolean useHolograms = true;

@ConfigComment("Hologram position - the offset to the magic block where holograms will appear")
@ConfigEntry(path = "world.hologram-offset")
private String offset = "0.5, 1.1, 0.5";

@ConfigComment("Duration in seconds that phase holograms will exist after being displayed, if used.")
@ConfigComment("If set to 0, then holograms will persist until cleared some other way.")
@ConfigEntry(path = "world.hologram-duration")
Expand Down Expand Up @@ -2195,4 +2199,18 @@ public boolean isDisallowTeamMemberIslands() {
public void setDisallowTeamMemberIslands(boolean disallowTeamMemberIslands) {
this.disallowTeamMemberIslands = disallowTeamMemberIslands;
}

/**
* @return the offset
*/
public String getOffset() {
return offset;
}

/**
* @param offset the offset to set
*/
public void setOffset(String offset) {
this.offset = offset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull;

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

private TextDisplay createHologram(Island island) {
Location pos = island.getCenter().clone().add(0.5, 1.1, 0.5);
Location pos = island.getCenter().clone().add(parseVector(addon.getSettings().getOffset()));
World world = pos.getWorld();
assert world != null;

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

private static Vector parseVector(String str) {
if (str == null) {
return new Vector(0.5, 1.1, 0.5);
}
String[] parts = str.split(",");
if (parts.length != 3) {
return new Vector(0.5, 1.1, 0.5);
}

try {
double x = Double.parseDouble(parts[0].trim());
double y = Double.parseDouble(parts[1].trim());
double z = Double.parseDouble(parts[2].trim());
return new Vector(x, y, z);
} catch (NumberFormatException e) {
return new Vector(0.5, 1.1, 0.5);
}
}

private void clearIfInitialized(TextDisplay hologram) {
if (hologram.isValid()) {
hologram.remove();
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ world:
difficulty: NORMAL
# Display holograms
holograms: true
# Hologram position - the offset to the magic block where holograms will appear
hologram-offset: 0.5, 1.1, 0.5
# Duration in seconds that phase holograms will exist after being displayed, if used.
# If set to 0, then holograms will persist until cleared some other way.
hologram-duration: 10
Expand Down Expand Up @@ -193,9 +195,9 @@ world:
create-obsidian-platform: false
# Mob white list - these mobs will NOT be removed when logging in or doing /island
remove-mobs-whitelist:
- WITHER
- ZOMBIE_VILLAGER
- ENDERMAN
- ZOMBIE_VILLAGER
- WITHER
# World flags. These are boolean settings for various flags for this world
flags:
CREEPER_DAMAGE: true
Expand Down

0 comments on commit 91a2cc7

Please sign in to comment.