Use Position instead of ImmutablePosition where possible

This commit is contained in:
filoghost 2022-05-22 21:01:32 +02:00
parent 525622b59a
commit d35648b4e4
10 changed files with 30 additions and 31 deletions

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.FeatureSupport;
import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.ErrorCollector;
import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.logging.Log;
import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI; import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.core.HolographicDisplaysCore; import me.filoghost.holographicdisplays.core.HolographicDisplaysCore;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.bridge.bungeecord.BungeeServerTracker; import me.filoghost.holographicdisplays.plugin.bridge.bungeecord.BungeeServerTracker;
import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook; import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook;
import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager; import me.filoghost.holographicdisplays.plugin.commands.HologramCommandManager;
@ -137,7 +137,7 @@ public class HolographicDisplays extends FCommonsPlugin {
for (InternalHologramConfig hologramConfig : hologramConfigs) { for (InternalHologramConfig hologramConfig : hologramConfigs) {
try { try {
List<InternalHologramLine> lines = hologramConfig.deserializeLines(); List<InternalHologramLine> lines = hologramConfig.deserializeLines();
ImmutablePosition position = hologramConfig.deserializePosition(); Position position = hologramConfig.deserializePosition();
InternalHologram hologram = internalHologramManager.createHologram(hologramConfig.getName(), position); InternalHologram hologram = internalHologramManager.createHologram(hologramConfig.getName(), position);
hologram.addLines(lines); hologram.addLines(lines);
} catch (InternalHologramLoadException e) { } catch (InternalHologramLoadException e) {

View File

@ -8,11 +8,11 @@ package me.filoghost.holographicdisplays.plugin.commands;
import me.filoghost.fcommons.Strings; import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.command.validation.CommandException; import me.filoghost.fcommons.command.validation.CommandException;
import me.filoghost.fcommons.command.validation.CommandValidate; import me.filoghost.fcommons.command.validation.CommandValidate;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.plugin.config.ConfigManager; import me.filoghost.holographicdisplays.plugin.config.ConfigManager;
import me.filoghost.holographicdisplays.plugin.config.InternalHologramLineParser; import me.filoghost.holographicdisplays.plugin.config.InternalHologramLineParser;
import me.filoghost.holographicdisplays.plugin.config.InternalHologramLoadException; import me.filoghost.holographicdisplays.plugin.config.InternalHologramLoadException;
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType; import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramLine; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramLine;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramManager; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramManager;
@ -71,7 +71,7 @@ public class InternalHologramEditor {
return internalHologramManager.getHolograms(); return internalHologramManager.getHolograms();
} }
public InternalHologram create(String hologramName, ImmutablePosition spawnPosition) { public InternalHologram create(String hologramName, Position spawnPosition) {
return internalHologramManager.createHologram(hologramName, spawnPosition); return internalHologramManager.createHologram(hologramName, spawnPosition);
} }

View File

@ -8,11 +8,11 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
import me.filoghost.fcommons.command.sub.SubCommandContext; import me.filoghost.fcommons.command.sub.SubCommandContext;
import me.filoghost.fcommons.command.validation.CommandException; import me.filoghost.fcommons.command.validation.CommandException;
import me.filoghost.fcommons.command.validation.CommandValidate; import me.filoghost.fcommons.command.validation.CommandValidate;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand; import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor; import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType; import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
import me.filoghost.holographicdisplays.plugin.format.ColorScheme; import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -36,19 +36,19 @@ public class AlignCommand extends HologramSubCommand {
CommandValidate.check(hologram != referenceHologram, "The holograms must not be the same."); CommandValidate.check(hologram != referenceHologram, "The holograms must not be the same.");
ImmutablePosition referencePosition = referenceHologram.getPosition(); Position referencePosition = referenceHologram.getPosition();
ImmutablePosition newPosition = hologram.getPosition(); Position oldPosition = hologram.getPosition();
Position newPosition;
String axis = args[0]; String axis = args[0];
if (axis.equalsIgnoreCase("x")) { if (axis.equalsIgnoreCase("x")) {
newPosition = newPosition.withX(referencePosition.getX()); newPosition = Position.of(oldPosition.getWorldName(), referencePosition.getX(), oldPosition.getY(), oldPosition.getZ());
} else if (axis.equalsIgnoreCase("y")) { } else if (axis.equalsIgnoreCase("y")) {
newPosition = newPosition.withY(referencePosition.getY()); newPosition = Position.of(oldPosition.getWorldName(), oldPosition.getX(), referencePosition.getY(), oldPosition.getZ());
} else if (axis.equalsIgnoreCase("z")) { } else if (axis.equalsIgnoreCase("z")) {
newPosition = newPosition.withZ(referencePosition.getZ()); newPosition = Position.of(oldPosition.getWorldName(), oldPosition.getX(), oldPosition.getY(), referencePosition.getZ());
} else if (axis.equalsIgnoreCase("xz")) { } else if (axis.equalsIgnoreCase("xz")) {
newPosition = newPosition.withX(referencePosition.getX()); newPosition = Position.of(oldPosition.getWorldName(), referencePosition.getX(), oldPosition.getY(), referencePosition.getZ());
newPosition = newPosition.withZ(referencePosition.getZ());
} else { } else {
throw new CommandException("You must specify either X, Y, Z or XZ, " + axis + " is not a valid axis."); throw new CommandException("You must specify either X, Y, Z or XZ, " + axis + " is not a valid axis.");
} }

View File

@ -9,13 +9,13 @@ import me.filoghost.fcommons.Strings;
import me.filoghost.fcommons.command.sub.SubCommandContext; import me.filoghost.fcommons.command.sub.SubCommandContext;
import me.filoghost.fcommons.command.validation.CommandException; import me.filoghost.fcommons.command.validation.CommandException;
import me.filoghost.fcommons.command.validation.CommandValidate; import me.filoghost.fcommons.command.validation.CommandValidate;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand; import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor; import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramLine;
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType; import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
import me.filoghost.holographicdisplays.plugin.format.ColorScheme; import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramLine;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -46,7 +46,7 @@ public class CreateCommand extends HologramSubCommand {
"The name must contain only alphanumeric characters, underscores and hyphens."); "The name must contain only alphanumeric characters, underscores and hyphens.");
CommandValidate.check(!hologramEditor.hologramExists(hologramName), "A hologram with that name already exists."); CommandValidate.check(!hologramEditor.hologramExists(hologramName), "A hologram with that name already exists.");
ImmutablePosition spawnPosition = ImmutablePosition.of(player.getLocation()); Position spawnPosition = Position.of(player);
boolean moveUp = player.isOnGround(); boolean moveUp = player.isOnGround();
if (moveUp) { if (moveUp) {

View File

@ -8,11 +8,11 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
import me.filoghost.fcommons.command.sub.SubCommandContext; import me.filoghost.fcommons.command.sub.SubCommandContext;
import me.filoghost.fcommons.command.validation.CommandException; import me.filoghost.fcommons.command.validation.CommandException;
import me.filoghost.fcommons.command.validation.CommandValidate; import me.filoghost.fcommons.command.validation.CommandValidate;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand; import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor; import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType; import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
import me.filoghost.holographicdisplays.plugin.format.ColorScheme; import me.filoghost.holographicdisplays.plugin.format.ColorScheme;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -35,7 +35,7 @@ public class MoveHereCommand extends HologramSubCommand {
Player player = CommandValidate.getPlayerSender(sender); Player player = CommandValidate.getPlayerSender(sender);
InternalHologram hologram = hologramEditor.getExistingHologram(args[0]); InternalHologram hologram = hologramEditor.getExistingHologram(args[0]);
hologram.setPosition(ImmutablePosition.of(player.getLocation())); hologram.setPosition(Position.of(player));
hologramEditor.saveChanges(hologram, ChangeType.EDIT_POSITION); hologramEditor.saveChanges(hologram, ChangeType.EDIT_POSITION);
hologramEditor.teleportLookingDown(player, player.getLocation()); hologramEditor.teleportLookingDown(player, player.getLocation());

View File

@ -8,10 +8,10 @@ package me.filoghost.holographicdisplays.plugin.commands.subs;
import me.filoghost.fcommons.command.sub.SubCommandContext; import me.filoghost.fcommons.command.sub.SubCommandContext;
import me.filoghost.fcommons.command.validation.CommandException; import me.filoghost.fcommons.command.validation.CommandException;
import me.filoghost.fcommons.command.validation.CommandValidate; import me.filoghost.fcommons.command.validation.CommandValidate;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand; import me.filoghost.holographicdisplays.plugin.commands.HologramSubCommand;
import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor; import me.filoghost.holographicdisplays.plugin.commands.InternalHologramEditor;
import me.filoghost.holographicdisplays.plugin.format.DisplayFormat; import me.filoghost.holographicdisplays.plugin.format.DisplayFormat;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -41,7 +41,7 @@ public class NearCommand extends HologramSubCommand {
List<InternalHologram> nearHolograms = new ArrayList<>(); List<InternalHologram> nearHolograms = new ArrayList<>();
for (InternalHologram hologram : hologramEditor.getHolograms()) { for (InternalHologram hologram : hologramEditor.getHolograms()) {
ImmutablePosition position = hologram.getPosition(); Position position = hologram.getPosition();
if (position.isInSameWorld(player) && position.distance(player) <= radius) { if (position.isInSameWorld(player) && position.distance(player) <= radius) {
nearHolograms.add(hologram); nearHolograms.add(hologram);
} }

View File

@ -9,7 +9,6 @@ import me.filoghost.fcommons.collection.CollectionUtils;
import me.filoghost.fcommons.config.ConfigSection; import me.filoghost.fcommons.config.ConfigSection;
import me.filoghost.fcommons.config.exception.ConfigValueException; import me.filoghost.fcommons.config.exception.ConfigValueException;
import me.filoghost.holographicdisplays.api.beta.Position; import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramLine; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologramLine;
@ -77,7 +76,7 @@ public class InternalHologramConfig {
return positionConfigSection; return positionConfigSection;
} }
public ImmutablePosition deserializePosition() throws InternalHologramLoadException { public Position deserializePosition() throws InternalHologramLoadException {
ConfigSection positionConfigSection = configSection.getConfigSection("position"); ConfigSection positionConfigSection = configSection.getConfigSection("position");
if (positionConfigSection == null) { if (positionConfigSection == null) {
@ -89,7 +88,7 @@ public class InternalHologramConfig {
double x = positionConfigSection.getRequiredDouble("x"); double x = positionConfigSection.getRequiredDouble("x");
double y = positionConfigSection.getRequiredDouble("y"); double y = positionConfigSection.getRequiredDouble("y");
double z = positionConfigSection.getRequiredDouble("z"); double z = positionConfigSection.getRequiredDouble("z");
return new ImmutablePosition(worldName, x, y, z); return Position.of(worldName, x, y, z);
} catch (ConfigValueException e) { } catch (ConfigValueException e) {
throw new InternalHologramLoadException("invalid position attribute \"" + e.getConfigPath() + "\"", e); throw new InternalHologramLoadException("invalid position attribute \"" + e.getConfigPath() + "\"", e);
} }

View File

@ -7,8 +7,8 @@
package me.filoghost.holographicdisplays.plugin.format; package me.filoghost.holographicdisplays.plugin.format;
import me.filoghost.fcommons.Colors; import me.filoghost.fcommons.Colors;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.plugin.config.StaticReplacements; import me.filoghost.holographicdisplays.plugin.config.StaticReplacements;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram; import me.filoghost.holographicdisplays.plugin.internal.hologram.InternalHologram;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@ -93,7 +93,7 @@ public class DisplayFormat {
} }
public static void sendHologramSummary(CommandSender sender, InternalHologram hologram, boolean showWorld) { public static void sendHologramSummary(CommandSender sender, InternalHologram hologram, boolean showWorld) {
ImmutablePosition position = hologram.getPosition(); Position position = hologram.getPosition();
sender.sendMessage(ColorScheme.SECONDARY_DARK + "- " + ColorScheme.SECONDARY_BOLD + hologram.getName() sender.sendMessage(ColorScheme.SECONDARY_DARK + "- " + ColorScheme.SECONDARY_BOLD + hologram.getName()
+ ColorScheme.SECONDARY_DARK + " (" + hologram.getLines().size() + " lines) at " + ColorScheme.SECONDARY_DARK + " (" + hologram.getLines().size() + " lines) at "
+ (showWorld ? "world: \"" + position.getWorldName() + "\", " : "") + (showWorld ? "world: \"" + position.getWorldName() + "\", " : "")

View File

@ -6,11 +6,11 @@
package me.filoghost.holographicdisplays.plugin.internal.hologram; package me.filoghost.holographicdisplays.plugin.internal.hologram;
import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI; import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.api.beta.Position;
import me.filoghost.holographicdisplays.api.beta.hologram.Hologram; import me.filoghost.holographicdisplays.api.beta.hologram.Hologram;
import me.filoghost.holographicdisplays.api.beta.hologram.PlaceholderSetting; import me.filoghost.holographicdisplays.api.beta.hologram.PlaceholderSetting;
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent; import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent;
import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType; import me.filoghost.holographicdisplays.plugin.event.InternalHologramChangeEvent.ChangeType;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,12 +21,12 @@ public class InternalHologram {
private final Hologram renderedHologram; private final Hologram renderedHologram;
private final String name; private final String name;
private ImmutablePosition position; private Position position;
private final List<InternalHologramLine> lines; private final List<InternalHologramLine> lines;
private final List<InternalHologramLine> unmodifiableLinesView; private final List<InternalHologramLine> unmodifiableLinesView;
private boolean deleted; private boolean deleted;
public InternalHologram(HolographicDisplaysAPI api, String name, ImmutablePosition position) { public InternalHologram(HolographicDisplaysAPI api, String name, Position position) {
this.renderedHologram = api.createHologram(position); this.renderedHologram = api.createHologram(position);
this.renderedHologram.setPlaceholderSetting(PlaceholderSetting.ENABLE_ALL); this.renderedHologram.setPlaceholderSetting(PlaceholderSetting.ENABLE_ALL);
this.name = name; this.name = name;
@ -43,11 +43,11 @@ public class InternalHologram {
return name; return name;
} }
public ImmutablePosition getPosition() { public Position getPosition() {
return position; return position;
} }
public void setPosition(ImmutablePosition position) { public void setPosition(Position position) {
checkNotDeleted(); checkNotDeleted();
this.position = position; this.position = position;
updateRendering(); updateRendering();

View File

@ -6,7 +6,7 @@
package me.filoghost.holographicdisplays.plugin.internal.hologram; package me.filoghost.holographicdisplays.plugin.internal.hologram;
import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI; import me.filoghost.holographicdisplays.api.beta.HolographicDisplaysAPI;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition; import me.filoghost.holographicdisplays.api.beta.Position;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +32,7 @@ public class InternalHologramManager {
return null; return null;
} }
public InternalHologram createHologram(String name, ImmutablePosition position) { public InternalHologram createHologram(String name, Position position) {
if (getHologramByName(name) != null) { if (getHologramByName(name) != null) {
throw new IllegalStateException("hologram named \"" + name + "\" already exists"); throw new IllegalStateException("hologram named \"" + name + "\" already exists");
} }