Skip to content

Commit 7e5d290

Browse files
committed
add a boolean check for bottom location
1 parent 38ab038 commit 7e5d290

File tree

5 files changed

+15
-90
lines changed

5 files changed

+15
-90
lines changed

common/src/main/java/me/hsgamer/unihologram/common/api/Hologram.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,13 @@ default int size() {
119119
* @param location the location
120120
*/
121121
void setLocation(T location);
122+
123+
/**
124+
* Check if the location is at the bottom of the hologram
125+
*
126+
* @return true if it is
127+
*/
128+
default boolean isLocationBottom() {
129+
return false;
130+
}
122131
}

display/src/main/java/me/hsgamer/unihologram/display/DisplayHologram.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,8 @@ public interface DisplayHologram<T> extends Hologram<T> {
108108
*/
109109
void setAlignment(DisplayTextAlignment alignment);
110110

111-
/**
112-
* Get the origin location.
113-
* This is the location of the text display, while {@link Hologram#getLocation()} is the location of the top of the display.
114-
*
115-
* @return the origin location
116-
*/
117-
T getOriginLocation();
118-
119-
/**
120-
* Set the origin location
121-
*
122-
* @param originLocation the origin location
123-
* @see #getOriginLocation()
124-
*/
125-
void setOriginLocation(T originLocation);
111+
@Override
112+
default boolean isLocationBottom() {
113+
return true;
114+
}
126115
}

spigot/fancyholograms/src/main/java/me/hsgamer/unihologram/spigot/fancyholograms/hologram/FHHologram.java

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@
2828
import java.awt.*;
2929
import java.util.ArrayList;
3030
import java.util.List;
31-
import java.util.Objects;
3231
import java.util.function.Consumer;
3332
import java.util.stream.Collectors;
3433

3534
/**
3635
* The hologram for FancyHolograms
3736
*/
3837
public class FHHologram implements me.hsgamer.unihologram.common.api.Hologram<Location>, Colored, PlayerVisibility, DisplayHologram<Location> {
39-
private static final double LINE_HEIGHT = 0.25;
4038
private final Hologram hologram;
4139

4240
/**
@@ -60,36 +58,6 @@ public FHHologram(Hologram hologram) {
6058
this.hologram = hologram;
6159
}
6260

63-
private static Location getTopLocation(Location location, float scale, int lineCount) {
64-
Location newLocation = Objects.requireNonNull(location).clone();
65-
newLocation.setY(newLocation.getY() + LINE_HEIGHT * scale * lineCount);
66-
return newLocation;
67-
}
68-
69-
private static Location getBottomLocation(Location location, float yScale, int lineCount) {
70-
Location newLocation = Objects.requireNonNull(location).clone();
71-
newLocation.setY(newLocation.getY() - LINE_HEIGHT * yScale * lineCount);
72-
return newLocation;
73-
}
74-
75-
private Location getTopLocation() {
76-
return getTopLocation(hologram.getData().getLocation(), hologram.getData().getScale().y, hologram.getData().getText().size());
77-
}
78-
79-
private void setTopLocation(Location location) {
80-
hologram.getData().setLocation(getBottomLocation(location, hologram.getData().getScale().y, hologram.getData().getText().size()));
81-
}
82-
83-
private void updateTopLocation(float yScale, int lineCount) {
84-
Location topLocation = getTopLocation(hologram.getData().getLocation(), hologram.getData().getScale().y, hologram.getData().getText().size());
85-
Location bottomLocation = getBottomLocation(topLocation, yScale, lineCount);
86-
hologram.getData().setLocation(bottomLocation);
87-
}
88-
89-
private void updateTopLocation(int lineCount) {
90-
updateTopLocation(hologram.getData().getScale().y, lineCount);
91-
}
92-
9361
private void checkHologramInitialized() {
9462
Preconditions.checkArgument(isInitialized(), "Hologram is not initialized");
9563
}
@@ -132,7 +100,6 @@ private void editLine(Consumer<List<HologramLine>> consumer) {
132100
checkHologramInitialized();
133101
List<HologramLine> lines = new ArrayList<>(getLines());
134102
consumer.accept(lines);
135-
updateTopLocation(lines.size());
136103
setLines(lines);
137104
}
138105

@@ -178,13 +145,13 @@ public boolean isInitialized() {
178145
@Override
179146
public Location getLocation() {
180147
checkHologramInitialized();
181-
return getTopLocation();
148+
return hologram.getData().getLocation();
182149
}
183150

184151
@Override
185152
public void setLocation(Location location) {
186153
checkHologramInitialized();
187-
setTopLocation(location);
154+
hologram.getData().setLocation(location);
188155
updateHologram();
189156
}
190157

@@ -242,7 +209,6 @@ public DisplayScale getScale() {
242209
@Override
243210
public void setScale(DisplayScale scale) {
244211
checkHologramInitialized();
245-
updateTopLocation(scale.y, hologram.getData().getText().size());
246212
hologram.getData().setScale(scale.x, scale.y, scale.z);
247213
updateHologram();
248214
}
@@ -350,17 +316,4 @@ public void setAlignment(DisplayTextAlignment alignment) {
350316
}
351317
updateHologram();
352318
}
353-
354-
@Override
355-
public Location getOriginLocation() {
356-
checkHologramInitialized();
357-
return hologram.getData().getLocation();
358-
}
359-
360-
@Override
361-
public void setOriginLocation(Location originLocation) {
362-
checkHologramInitialized();
363-
hologram.getData().setLocation(originLocation);
364-
updateHologram();
365-
}
366319
}

spigot/test/src/main/java/me/hsgamer/unihologram/spigot/test/command/MainCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public MainCommand(UniHologramTest plugin) {
2323
subCommandManager.registerSubcommand(new MoveCommand(plugin));
2424
subCommandManager.registerSubcommand(new BackgroundColorCommand(plugin));
2525
subCommandManager.registerSubcommand(new BillboardCommand(plugin));
26-
subCommandManager.registerSubcommand(new MoveOriginCommand(plugin));
2726
subCommandManager.registerSubcommand(new ScaleCommand(plugin));
2827
subCommandManager.registerSubcommand(new ShadowedCommand(plugin));
2928
subCommandManager.registerSubcommand(new ShadowRadiusCommand(plugin));

spigot/test/src/main/java/me/hsgamer/unihologram/spigot/test/command/subcommand/MoveOriginCommand.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)