-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added new property `Viewer` for hologram. #99 * Revert "Added new property `Viewer` for hologram. #99" This reverts commit 63b95c9. * Added predicate for visibility * Pr fixes. * Added migration for visibility to visible_by_default * Pr fixes. * Added old API and improve javadocs. * Added list for Manual visibility. * Revert "Added list for Manual visibility." This reverts commit 9d2a711.
- Loading branch information
Showing
6 changed files
with
144 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
api/src/main/java/de/oliver/fancyholograms/api/data/property/visibility/Visibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.oliver.fancyholograms.api.data.property.visibility; | ||
|
||
import de.oliver.fancyholograms.api.Hologram; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
public enum Visibility { | ||
/** | ||
* Everybody can see a hologram. | ||
*/ | ||
ALL((player, hologram) -> true), | ||
/** | ||
* Manual control. | ||
*/ | ||
MANUAL((player, hologram) -> hologram.isShown(player)), | ||
/** | ||
* The player needs permission to see a specific hologram. | ||
*/ | ||
PERMISSION_REQUIRED( | ||
(player, hologram) -> player.hasPermission("fancyholograms.viewhologram." + hologram.getData().getName()) | ||
); | ||
|
||
|
||
private final VisibilityPredicate predicate; | ||
|
||
|
||
Visibility(VisibilityPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
|
||
public boolean canSee(Player player, Hologram hologram) { | ||
return this.predicate.canSee(player, hologram); | ||
} | ||
|
||
|
||
public static Optional<Visibility> byString(String value) { | ||
return Arrays.stream(Visibility.values()) | ||
.filter(visibility -> visibility.toString().equalsIgnoreCase(value)) | ||
.findFirst(); | ||
} | ||
|
||
public interface VisibilityPredicate { | ||
|
||
boolean canSee(Player player, Hologram hologram); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters