Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Hologram constructors to enforce non-null config #269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Collection;
Expand Down Expand Up @@ -266,7 +265,7 @@ public Hologram(@NonNull String name, @NonNull Location location) {
* @see eu.decentsoftware.holograms.api.DHAPI#createHologram(String, Location, boolean)
*/
public Hologram(@NonNull String name, @NonNull Location location, boolean saveToFile) {
this(name, location, saveToFile ? new FileConfig(DECENT_HOLOGRAMS.getPlugin(), String.format("holograms/%s.yml", name)) : null);
this(name, location, new FileConfig(DECENT_HOLOGRAMS.getPlugin(), String.format("holograms/%s.yml", name)), true, saveToFile);
}

/**
Expand All @@ -276,7 +275,7 @@ public Hologram(@NonNull String name, @NonNull Location location, boolean saveTo
* @param location The location of the hologram.
* @param config The config of the hologram.
*/
public Hologram(@NonNull String name, @NonNull Location location, @Nullable FileConfig config) {
public Hologram(@NonNull String name, @NonNull Location location, @NonNull FileConfig config) {
this(name, location, config, true);
}

Expand All @@ -288,12 +287,25 @@ public Hologram(@NonNull String name, @NonNull Location location, @Nullable File
* @param config The config of the hologram.
* @param enabled Whether the hologram should be enabled.
*/
public Hologram(@NonNull String name, @NonNull Location location, @Nullable FileConfig config, boolean enabled) {
public Hologram(@NonNull String name, @NonNull Location location, @NonNull FileConfig config, boolean enabled) {
this(name, location, config, enabled, true);
}

/**
* Creates a new Hologram with the given parameters.
*
* @param name The name of the hologram.
* @param location The location of the hologram.
* @param config The config of the hologram.
* @param enabled Whether the hologram should be enabled.
* @param saveToFile Whether the hologram should be saved to a file.
*/
public Hologram(@NonNull String name, @NonNull Location location, @NonNull FileConfig config, boolean enabled, boolean saveToFile) {
super(location);
this.name = name;
this.config = config;
this.enabled = enabled;
this.saveToFile = this.config != null;
this.name = name;
this.saveToFile = saveToFile;
this.tickCounter = new AtomicInteger();
this.addPage();
this.register();
Expand Down Expand Up @@ -346,9 +358,7 @@ public String toString() {
@Override
public void delete() {
super.delete();
if (config != null) {
config.delete();
}
config.delete();
}

/**
Expand Down