Rename API methods

This commit is contained in:
filoghost 2021-10-03 15:50:46 +02:00
parent 1a9a80fe36
commit fdd76f179e
3 changed files with 44 additions and 45 deletions

View File

@ -9,57 +9,56 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* Settings to manage the visibility of a hologram to players. Allows to set both the default visibility and the * Settings to manage the visibility of a hologram to players. Allows to set a global visibility and an individual
* visibility to a specific player. * visibility for specific players.
* *
* @since 1 * @since 1
*/ */
public interface VisibilitySettings { public interface VisibilitySettings {
/** /**
* Returns the default visibility of the hologram. The initial value is {@link Visibility#VISIBLE}, meaning that the * Returns the visibility of the hologram. The initial value is {@link Visibility#VISIBLE}.
* hologram is visible to everyone.
* *
* @return the default visibility * @return the visibility
* @since 1 * @since 1
*/ */
@NotNull Visibility getDefaultVisibility(); @NotNull Visibility getVisibility();
/** /**
* Sets the default visibility. This value affects player which do not have an individual visibility set with {@link * Sets the visibility of the hologram. This value only affects player which do not have an individual visibility
* #setIndividualVisibility(Player, Visibility)} and player whose individual visibility has been reset with {@link * (see {@link #setIndividualVisibility(Player, Visibility)}).
* #resetIndividualVisibility(Player)}.
* *
* @param defaultVisibility the new default visibility * @param visibility the new visibility
* @since 1 * @since 1
*/ */
void setDefaultVisibility(@NotNull Visibility defaultVisibility); void setVisibility(@NotNull Visibility visibility);
/** /**
* Sets the visibility for a specific player, overriding the default value ({@link #getDefaultVisibility()}). * Sets the visibility for a specific player, overriding the global value of ({@link #getVisibility()}).
* The individual visibility value can be reverted with {@link #resetIndividualVisibility(Player)}. * The individual visibility value can be removed with {@link #removeIndividualVisibility(Player)}.
* *
* @since 1 * @since 1
*/ */
void setIndividualVisibility(@NotNull Player player, @NotNull Visibility visibility); void setIndividualVisibility(@NotNull Player player, @NotNull Visibility visibility);
/** /**
* Resets the visibility for a specific player to the default value ({@link #getDefaultVisibility()}). * Removes the individual visibility for a player. The visibility for the player would then be determined by the
* global visibility ({@link #getVisibility()}).
* *
* @since 1 * @since 1
*/ */
void resetIndividualVisibility(@NotNull Player player); void removeIndividualVisibility(@NotNull Player player);
/** /**
* Resets the visibility for all players to the default value ({@link #getDefaultVisibility()}). * Removes the individual visibility all players which have one.
* *
* @since 1 * @since 1
*/ */
void resetIndividualVisibilityAll(); void clearIndividualVisibilities();
/** /**
* Checks if a hologram is visible to a player, taking into account the individual visibility for the specific * Checks if a hologram is visible to a player, taking into account both the global visibility and the individual
* player and the default visibility. * visibility of the player (if set).
* *
* @param player the player * @param player the player
* @return if the player can see the hologram * @return if the player can see the hologram

View File

@ -16,34 +16,34 @@ import java.util.concurrent.ConcurrentHashMap;
public class DefaultVisibilitySettings implements VisibilitySettings { public class DefaultVisibilitySettings implements VisibilitySettings {
private Map<UUID, Visibility> visibilityByPlayer; private Visibility globalVisibility;
private Visibility defaultVisibility; private Map<UUID, Visibility> individualVisibilities;
public DefaultVisibilitySettings() { public DefaultVisibilitySettings() {
this.defaultVisibility = Visibility.VISIBLE; this.globalVisibility = Visibility.VISIBLE;
} }
@Override @Override
public @NotNull Visibility getDefaultVisibility() { public @NotNull Visibility getVisibility() {
return defaultVisibility; return globalVisibility;
} }
@Override @Override
public void setDefaultVisibility(@NotNull Visibility defaultVisibility) { public void setVisibility(@NotNull Visibility visibility) {
if (this.defaultVisibility == defaultVisibility) { if (this.globalVisibility == visibility) {
return; return;
} }
this.defaultVisibility = defaultVisibility; this.globalVisibility = visibility;
} }
@Override @Override
public void setIndividualVisibility(@NotNull Player player, @NotNull Visibility visibility) { public void setIndividualVisibility(@NotNull Player player, @NotNull Visibility visibility) {
// Lazy initialization // Lazy initialization
if (visibilityByPlayer == null) { if (individualVisibilities == null) {
visibilityByPlayer = new ConcurrentHashMap<>(); individualVisibilities = new ConcurrentHashMap<>();
} }
visibilityByPlayer.put(player.getUniqueId(), visibility); individualVisibilities.put(player.getUniqueId(), visibility);
} }
@Override @Override
@ -54,41 +54,41 @@ public class DefaultVisibilitySettings implements VisibilitySettings {
} }
private Visibility getVisibility(Player player) { private Visibility getVisibility(Player player) {
if (visibilityByPlayer != null) { if (individualVisibilities != null) {
Visibility visibility = visibilityByPlayer.get(player.getUniqueId()); Visibility visibility = individualVisibilities.get(player.getUniqueId());
if (visibility != null) { if (visibility != null) {
return visibility; return visibility;
} }
} }
return defaultVisibility; return globalVisibility;
} }
@Override @Override
public void resetIndividualVisibility(@NotNull Player player) { public void removeIndividualVisibility(@NotNull Player player) {
Preconditions.notNull(player, "player"); Preconditions.notNull(player, "player");
if (visibilityByPlayer == null) { if (individualVisibilities == null) {
return; return;
} }
visibilityByPlayer.remove(player.getUniqueId()); individualVisibilities.remove(player.getUniqueId());
} }
@Override @Override
public void resetIndividualVisibilityAll() { public void clearIndividualVisibilities() {
if (visibilityByPlayer == null) { if (individualVisibilities == null) {
return; return;
} }
visibilityByPlayer.clear(); individualVisibilities.clear();
} }
@Override @Override
public String toString() { public String toString() {
return "VisibilitySettings{" return "VisibilitySettings{"
+ "defaultVisibility=" + defaultVisibility + "globalVisibility=" + globalVisibility
+ ", visibilityByPlayer=" + visibilityByPlayer + ", individualVisibilities=" + individualVisibilities
+ "}"; + "}";
} }

View File

@ -21,12 +21,12 @@ class V2VisibilityManager implements VisibilityManager {
@Override @Override
public boolean isVisibleByDefault() { public boolean isVisibleByDefault() {
return v3VisibilitySettings.getDefaultVisibility() == Visibility.VISIBLE; return v3VisibilitySettings.getVisibility() == Visibility.VISIBLE;
} }
@Override @Override
public void setVisibleByDefault(boolean visibleByDefault) { public void setVisibleByDefault(boolean visibleByDefault) {
v3VisibilitySettings.setDefaultVisibility(visibleByDefault ? Visibility.VISIBLE : Visibility.HIDDEN); v3VisibilitySettings.setVisibility(visibleByDefault ? Visibility.VISIBLE : Visibility.HIDDEN);
} }
@Override @Override
@ -46,12 +46,12 @@ class V2VisibilityManager implements VisibilityManager {
@Override @Override
public void resetVisibility(Player player) { public void resetVisibility(Player player) {
v3VisibilitySettings.resetIndividualVisibility(player); v3VisibilitySettings.removeIndividualVisibility(player);
} }
@Override @Override
public void resetVisibilityAll() { public void resetVisibilityAll() {
v3VisibilitySettings.resetIndividualVisibilityAll(); v3VisibilitySettings.clearIndividualVisibilities();
} }
} }