-
Notifications
You must be signed in to change notification settings - Fork 32
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
Added new property Viewer
for hologram. #99
#100
Conversation
via #99 |
I think it would be better to implement something into the current system instead of having 2 different sets of uuids, we could probably make the set of shown players into a map of uuids to boolean. The boolean value being a sort of "force view" which ignores permissions. There is likely a better solution than this too though |
@OakLoaf For memory obviously, but not for logic. This structure will complicate the management and editing of the code. |
If you wanna one structure for that. Need create some PlayerContext and control them. For next updates that context can be improved without edit current code. |
This current solution is not good for memory and I'm almost certain this isn't the best solution from a logic standpoint either. Another alternative would be to add a requiresPermission attribute that can be disabled. |
Yeah it's another solution by different way. So how can we fix #99? |
I think adding a permission option might be the feasible option |
May be convert
|
I think if we were to do something like that it'd make more sense to accept a predicate. |
From? I didn't understand you |
Or do you talk about API? Yeah it's possible, propably good idea. |
This reverts commit 63b95c9.
Only issue regarding that would be that there would need to be some way to save that predicate |
I personally think we should just stick with the |
@OakLoaf check this out please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these changes it would probably be a good idea to rename VisibleByDefault
to VisibleTo
@Nullable | ||
public static Visibility byString(String value) { | ||
return Arrays.stream(Visibility.values()) | ||
.filter(visibility -> visibility.toString().equalsIgnoreCase(value)) | ||
.findFirst().orElse(null); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be removed in favour of Enum#valueOf(String#toUpperCase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valueOf is throwable, for safe parsing null needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no instance where it returns null anyway, if it is null wouldn't there be issues in other places? If so the error would be more helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Optional ? :)
api/src/main/java/de/oliver/fancyholograms/api/data/property/visibility/Visibility.java
Outdated
Show resolved
Hide resolved
...src/main/java/de/oliver/fancyholograms/api/data/property/visibility/VisibilityPredicate.java
Outdated
Show resolved
Hide resolved
@@ -209,7 +209,8 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No | |||
yield FancyNpcsPlugin.get().getNpcManager().getAllNpcs().stream().map(npc -> npc.getData().getName()); | |||
} | |||
case "block" -> Arrays.stream(Material.values()).filter(Material::isBlock).map(Enum::name); | |||
case "seethrough", "visiblebydefault" -> Stream.of("true", "false"); | |||
case "seethrough" -> Stream.of("true", "false"); | |||
case "visiblebydefault" -> new VisibleByDefaultCMD().tabcompletion(sender, hologram, args).stream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new command object for every tabcomplete is probably not a good idea, I would just copy the contents of the method over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is should be refactored at all.
All CMDs impltement Subcommand with execute and tabcompletion methods.
final var visibleByDefault = Optional.of(config.getString( | ||
"visible_by_default", DisplayHologramData.DEFAULT_IS_VISIBLE.toString()) | ||
).map(Visibility::byString).orElse(DisplayHologramData.DEFAULT_IS_VISIBLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be a good idea to add backwards compatibility and support the old boolean option for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to check booleans and convert into Predicate?
On java layer or config too? |
I'd say in config too, with backwards compatibility kept if the new one isn't defined |
I can but you really want store deprecated fields? Are you sure that it won't confuse users? |
It would likely get automatically updated on auto-save anyways but I think that loading from the old config would mean that the pr is more likely to be merged sooner |
Right now old configuration supported. Boolean converting to Enum on save. |
Maybe we should rename the visibleByDefault command with just "visibility" |
Added migration for field visible_by_default. After launch old boolean value will be converted to one of the following modes: On save |
@OliverSchlueter @OakLoaf Is there something else? |
Not that I can think of, I will review this after work in a few hours |
src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java
Outdated
Show resolved
Hide resolved
src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java
Outdated
Show resolved
Hide resolved
src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java
Outdated
Show resolved
Hide resolved
src/main/java/de/oliver/fancyholograms/storage/FlatFileHologramStorage.java
Outdated
Show resolved
Hide resolved
@OakLoaf Fixed, check another comments please. |
All looks good to me |
Has this been tested in-game to make sure everything works and is backwards compatible? |
I tested that on v2 configuration works fine for me. Do you have an example of old (v1) configurations? |
This should do, just teleport it to your location test-text:
type: TEXT
location:
world: world
x: 45.06436912097689
y: 87.61627563479522
z: -90.4272584957459
yaw: -109.71094
pitch: 90.0
visibility_distance: -1
visible_by_default: true
scale_x: 1.0
scale_y: 1.0
scale_z: 1.0
shadow_radius: 0.0
shadow_strength: 1.0
text:
- Edit this line with /hologram edit text
- test with more words |
Configuration before: holograms:
test-text:
type: TEXT
location:
world: world
x: 45.06436912097689
y: 87.61627563479522
z: -90.4272584957459
yaw: -109.71094
pitch: 90.0
visibility_distance: -1
visible_by_default: true
scale_x: 1.0
scale_y: 1.0
scale_z: 1.0
shadow_radius: 0.0
shadow_strength: 1.0
text:
- Edit this line with /hologram edit text
- test with more words Configuration after stop the server version: 2 # DO NOT CHANGE
holograms:
test-text:
type: TEXT
location:
world: world
x: 81.10001790115858
y: 75.0
z: 71.98312464428668
yaw: -165.9294
pitch: 21.240873
scale_x: 1.0
scale_y: 1.0
scale_z: 1.0
shadow_radius: 0.0
shadow_strength: 1.0
visibility_distance: -1
visibility: ALL
text:
- Edit this line with /hologram edit text
- test with more words
text_shadow: false
see_through: false
text_alignment: center
update_text_interval: -1 |
Very nicee |
Configuration after stop the server version: 2 # DO NOT CHANGE
holograms:
test-text:
type: TEXT
location:
world: world
x: 81.10002136230469
y: 75.0
z: 71.98312377929688
yaw: -165.9294
pitch: 21.240873
scale_x: 1.0
scale_y: 1.0
scale_z: 1.0
shadow_radius: 0.0
shadow_strength: 1.0
visibility_distance: -1
visibility: PERMISSION_REQUIRED
text:
- Edit this line with /hologram edit text
- test with more words
text_shadow: false
see_through: false
text_alignment: center
update_text_interval: -1 |
@OakLoaf setVisibleByDefault(boolean){
setVisiible(boolean?ALL:PERMS_REQUIRED):
} What do you think? |
Yeahh that's good just pop some spaces in there so it's more readable: |
Yeah :) ofc it's was just a draft code. I did it. |
I really don't think this added commit should be part of this PR. As far as I am aware Issue #99 was resolved as you can now input a custom predicate. The only issue you'd face is having it save, the only real fix for that would be to make the visibility enum into some sort of registry where people could register new visibility types, it'd just need to be done before FancyHolograms first loads the holograms. I'm not sure what @OliverSchlueter thinks of this as it does make it more complex but the manual visibility is just not a good solution in my eyes. |
It's talk about user frendly API. Do you make them implement the same type of logic every time, in every project, or do you implement once it for them? |
The whole reason we implemented a predicate was so that we wouldn't have to have 2 viewer lists. 2 lists is not necessary. |
But that second list will be allocated in a lot of projects whos using that plugin. This is balance of the user friendly. |
And you will repeat repeat that logic every time ;/ |
I completely disagree, the entirety of the most recent commit can be replaced with the predicate |
Nope, show is service field. |
In that case, an exception of some form could be implemented to ensure that they aren't removed in those instances. Although I imagine adding the visibility distance check into the predicate would probably the better solution here. |
Already, we can listen
This has a bad effect on performance and the difference in configuration |
My point like a user. I want to control who can and who can't see the hologram, I don't want to control the plugin processes (hiding due to distance or exiting the server) |
I agree that the issue needs a solution and will happily resolve that myself in a different pr. I've had a chat with Oliver and if you'd like to revert the most recent commit he'll happily merge this. |
This reverts commit 9d2a711.
Okay. |
Thank you for your contribution ❤️! |
Added a new property to the hologram instance.
This property specifies the list of players who are allowed to view this hologram. (Similar to a permission right now.)
If that solution is relevant, I can add command for that field.