Skip to content

Commit

Permalink
Merge pull request #25 from Matt-MX/dev
Browse files Browse the repository at this point in the history
🔥 Bump versions and fix groups bug
  • Loading branch information
Matt-MX authored Nov 6, 2024
2 parents 1b8b049 + 4768ecd commit 730d1b0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official
# Project configuration
group_name = com.mattmx
id = nametags
version = 1.2
version = 1.3

plugin_name = NameTags
plugin_main_class_name = NameTags
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ placeholderapi = "2.11.6"
ktgui = "2.4.2-alpha"
runPaper = "2.2.4"

packetEvents = "2.4.0"
entityLib = "2.4.9-SNAPSHOT"
packetEvents = "2.6.0"
entityLib = "2.4.11-SNAPSHOT"
tab = "4.1.8"

[libraries]
Expand Down
Binary file removed run/plugins/packetevents-spigot-2.4.0 (3).jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mattmx.nametags.config;

import com.mattmx.nametags.NameTags;
import com.mattmx.nametags.entity.NameTagEntity;
import com.mattmx.nametags.entity.trait.RefreshTrait;
import com.mattmx.nametags.entity.trait.SneakTrait;
import com.mattmx.nametags.event.NameTagEntityCreateEvent;
Expand All @@ -10,8 +11,12 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

public class ConfigDefaultsListener implements Listener {
private final @NotNull NameTags plugin;

Expand Down Expand Up @@ -46,47 +51,65 @@ public void onCreate(@NotNull NameTagEntityCreateEvent event) {
return;
}

event.getNameTag()
.getTraits()
.getOrAddTrait(RefreshTrait.class, () ->
RefreshTrait.ofMillis(
plugin,
refreshMillis,
(entity) -> {
synchronized (entity) {

// TODO we need to change the text based off the player the packet is being sent to.
TextDisplayMetaConfiguration.applyMeta(defaultSection(), entity.getMeta());
TextDisplayMetaConfiguration.applyTextMeta(defaultSection(), entity.getMeta(), player, player);

// TODO we should cache this stuff
plugin.getGroups()
.entrySet()
.stream()
.filter((e) -> player.hasPermission(e.getKey()))
.forEach((e) -> {
TextDisplayMetaConfiguration.applyMeta(e.getValue(), entity.getMeta());
TextDisplayMetaConfiguration.applyTextMeta(e.getValue(), entity.getMeta(), player, player);
});


if (entity.getMeta().getBillboardConstraints() == AbstractDisplayMeta.BillboardConstraints.CENTER) {
// Look passenger down to remove debug getting in the way
entity.getPassenger().rotateHead(0f, 90f);
registerDefaultRefreshListener(event.getNameTag(), refreshMillis);
}

public void registerDefaultRefreshListener(@NotNull NameTagEntity tag, long refreshMillis) {
Player player = (Player) tag.getBukkitEntity();

tag.getTraits().getOrAddTrait(RefreshTrait.class, () ->
RefreshTrait.ofMillis(
plugin,
refreshMillis,
(entity) -> {
synchronized (entity) {

// TODO we need to change the text based off the player the packet is being sent to.
TextDisplayMetaConfiguration.applyMeta(defaultSection(), entity.getMeta());
TextDisplayMetaConfiguration.applyTextMeta(defaultSection(), entity.getMeta(), player, player);

// TODO we should cache this stuff
List<Map.Entry<String, ConfigurationSection>> groups = plugin.getGroups()
.entrySet()
.stream()
.filter((e) -> player.hasPermission(e.getKey()))
.toList();

long recentRefreshEvery = plugin.getConfig().getLong("defaults.refresh-every", 50);
if (!groups.isEmpty()) {
Map.Entry<String, ConfigurationSection> highest = groups.getLast();

TextDisplayMetaConfiguration.applyMeta(highest.getValue(), entity.getMeta());
TextDisplayMetaConfiguration.applyTextMeta(highest.getValue(), entity.getMeta(), player, player);

long groupRefresh = highest.getValue().getLong("refresh-every", -1);
if (groupRefresh > 0) {
recentRefreshEvery = groupRefresh;
}
}

// Preserve background color for sneaking
// Maybe we should introduce an `afterRefresh` callback?
entity.getTraits()
.getTrait(SneakTrait.class)
.ifPresent(SneakTrait::manuallyUpdateSneakingOpacity);
if (recentRefreshEvery != refreshMillis) {
entity.getTraits().removeTrait(RefreshTrait.class);
registerDefaultRefreshListener(tag, recentRefreshEvery);
}

entity.updateVisibility();
entity.getPassenger().refresh();
if (entity.getMeta().getBillboardConstraints() == AbstractDisplayMeta.BillboardConstraints.CENTER) {
// Look passenger down to remove debug getting in the way
entity.getPassenger().rotateHead(0f, 90f);
}

// Preserve background color for sneaking
// Maybe we should introduce an `afterRefresh` callback?
entity.getTraits()
.getTrait(SneakTrait.class)
.ifPresent(SneakTrait::manuallyUpdateSneakingOpacity);

entity.updateVisibility();
entity.getPassenger().refresh();
}
)
);
}
)
);
}

}

0 comments on commit 730d1b0

Please sign in to comment.