Skip to content

Commit

Permalink
Fixup Default Tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Mar 7, 2024
1 parent 57e451a commit 58046c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group "xyz.oribuin"
version "1.2.4"
version "1.2.5"

java {
toolchain {
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/xyz/oribuin/eternaltags/manager/TagsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,34 +441,30 @@ public Tag getUserTag(@NotNull UUID uuid) {
*/
@Nullable
public Tag getUserTag(@NotNull Player player) {
DataManager dataManager = this.rosePlugin.getManager(DataManager.class);
TagUser user = dataManager.getCachedUsers().computeIfAbsent(player.getUniqueId(), k -> new TagUser(player));
DataManager data = this.rosePlugin.getManager(DataManager.class);
TagUser user = data.getCachedUsers().getOrDefault(player.getUniqueId(), new TagUser(player.getUniqueId()));
Tag tag = this.getTagFromId(user.getActiveTag());

// Check if the player is using a default tag.
if (user.isUsingDefaultTag() && this.usingDefaultTags) {
// Update the default tag for the user if they don't have one equipped
if (tag == null && this.usingDefaultTags) {
// Check if the player is using a default tag.
tag = this.getDefaultTag(player);
}

// Remove the tag if the player doesn't have permission to use it.
if (Setting.REMOVE_TAGS.getBoolean() && tag != null && !this.canUseTag(player, tag)) {
dataManager.removeUser(player.getUniqueId());
user.setActiveTag(null); // Remove the tag from the user.
user.setUsingDefaultTag(false); // Remove the default tag flag.
tag = null; // Set the tag to null.
if (tag != null) {
user.setActiveTag(tag.getId());
user.setUsingDefaultTag(true);
data.getCachedUsers().put(player.getUniqueId(), user);
}
}

// Use default tag if no active tag found.
if (tag == null && this.usingDefaultTags) {
tag = this.getDefaultTag(player);
if (tag == null)
return null;

user.setActiveTag(tag.getId());
user.setUsingDefaultTag(true);
// Remove the tag if the player doesn't have permission to use it.
if (Setting.REMOVE_TAGS.getBoolean() && tag != null && !this.canUseTag(player, tag) && !user.isUsingDefaultTag()) {
data.removeUser(player.getUniqueId());
user.setActiveTag(null);
user.setUsingDefaultTag(false);
tag = null;
}

dataManager.getCachedUsers().put(player.getUniqueId(), user);
return tag;
}

Expand Down

0 comments on commit 58046c4

Please # to comment.