Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import dev.frankheijden.insights.api.objects.wrappers.ScanObject;
import dev.frankheijden.insights.api.utils.StringUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
Expand All @@ -33,25 +32,19 @@
public class Messages {

private final InsightsPlugin plugin;
private final BukkitAudiences audiences;
private final YamlParser parser;
private final MiniMessage miniMessage;
private final Map<Key, String> messageCache;
private final TagResolver prefixResolver;

protected Messages(InsightsPlugin plugin, BukkitAudiences audiences, YamlParser parser) {
protected Messages(InsightsPlugin plugin, YamlParser parser) {
this.plugin = plugin;
this.audiences = audiences;
this.parser = parser;
this.miniMessage = MiniMessage.miniMessage();
this.messageCache = new EnumMap<>(Key.class);
this.prefixResolver = tagOf("prefix", miniMessage.deserialize(getRawMessage(Key.PREFIX)));
}

public BukkitAudiences getAudiences() {
return audiences;
}

public Message getMessage(Key messageKey) {
return createMessage(getRawMessage(messageKey));
}
Expand Down Expand Up @@ -93,7 +86,7 @@ private <T> Component addHover(Component component, T element, Component display

if (obj instanceof Material material) {
var key = material.getKey();
if (material.isItem()) {
if (material.isItem() && !material.isAir()) {
return component.hoverEvent(HoverEvent.showItem(
net.kyori.adventure.key.Key.key(key.getNamespace(), key.getKey()),
1
Expand Down Expand Up @@ -122,11 +115,10 @@ private <T> Component addHover(Component component, T element, Component display

public static Messages load(
InsightsPlugin plugin,
BukkitAudiences audiences,
File file,
InputStream defaultSettings
) throws IOException {
return new Messages(plugin, audiences, PassiveYamlParser.load(file, defaultSettings));
return new Messages(plugin, PassiveYamlParser.load(file, defaultSettings));
}

public static TagResolver tagOf(String name, String content) {
Expand Down Expand Up @@ -272,7 +264,14 @@ public Optional<Component> toComponent() {
* Sends the message to given receiver, using the message type defined.
*/
public void sendTo(CommandSender sender) {
sendTo(audiences.sender(sender));
if (content != null && !content.isEmpty()) {
var component = miniMessage.deserialize(content, resolver);
if (type == Type.ACTIONBAR) {
sender.sendActionBar(component);
} else {
sender.sendMessage(component);
}
}
}

/**
Expand Down Expand Up @@ -380,12 +379,10 @@ public void sendTo(CommandSender sender, int page) {
components.add(elementFormatFunction.apply(elements[i]));
}

var audience = audiences.sender(sender);

header.sendTo(sender);
components.forEach(audience::sendMessage);
components.forEach(sender::sendMessage);
footer.sendTo(sender);
audience.sendMessage(createFooter(page));
sender.sendMessage(createFooter(page));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public SendableNotification create() {
return new SendableNotification(content.resetTemplates()) {
@Override
public void send() {
var audiences = plugin.getMessages().getAudiences();
content.toComponent().ifPresent(component -> receivers.values()
.forEach(player -> audiences.player(player).sendActionBar(component)));
.forEach(player -> player.sendActionBar(component)));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected BossBarNotification(InsightsPlugin plugin, BossBar bossBar, Messages.M

@Override
public BossBarNotification add(Player player) {
receivers.add(plugin.getMessages().getAudiences().player(player));
receivers.add(player);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import dev.frankheijden.insights.tasks.PlayerTrackerTask;
import io.leangen.geantyref.TypeToken;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -86,7 +85,6 @@ public class Insights extends InsightsPlugin {
private InsightsPlaceholderExpansion placeholderExpansion;
private ScheduledTask playerTracker = null;
private ScheduledTask updateChecker = null;
private BukkitAudiences audiences = null;
private RedstoneUpdateCount redstoneUpdateCount = null;
private ChunkTeleport chunkTeleport;
private InsightsNMS nms;
Expand All @@ -107,7 +105,6 @@ public void onEnable() {
}
nms = InsightsNMS.get();

this.audiences = BukkitAudiences.create(this);
this.listenerManager = new ListenerManager(this);
reloadConfigs();

Expand Down Expand Up @@ -164,7 +161,6 @@ public void onDisable() {
placeholderExpansion = null;
}
chunkContainerExecutor.shutdown();
audiences.close();
}

@Override
Expand Down Expand Up @@ -201,7 +197,7 @@ public void reloadSettings() {
public void reloadMessages() {
File file = new File(getDataFolder(), MESSAGES_FILE_NAME);
try {
messages = Messages.load(this, this.audiences, file, getResource(MESSAGES_FILE_NAME));
messages = Messages.load(this, file, getResource(MESSAGES_FILE_NAME));
} catch (IOException ex) {
ex.printStackTrace();
}
Expand Down
6 changes: 0 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ subprojects {
dependencies {
compileOnly(libs.paperApi)
implementation(libs.bStatsBukkit)
implementation(libs.adventureApi)
implementation(libs.adventureMiniMessage)
implementation(libs.adventurePlatformBukkit)

if (!nms || nmsImpl) {
compileOnly(project(":Insights-NMS-Core"))
Expand Down Expand Up @@ -109,9 +106,6 @@ subprojects {
tasks.withType<ShadowJar> {
relocate("dev.frankheijden.minecraftreflection", "$dependencyDir.minecraftreflection")
relocate("org.bstats", "$dependencyDir.bstats")
relocate("net.kyori.adventure", "$dependencyDir.adventure")
relocate("net.kyori.examination", "$dependencyDir.examination")
relocate("net.kyori.option", "$dependencyDir.option")
if (nmsImpl) {
relocate(project.group.toString().replaceAfterLast('.', "impl"), project.group.toString())
}
Expand Down
5 changes: 0 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
semver = "0.10.2"
minecraft = "26.2.build.+"
bStats = "3.0.0"
adventure = "4.17.0"
adventurePlatformBukkit = "4.4.1"
assertj = "3.23.1"
mockito = "4.11.0"
jupiter = "5.9.1"
Expand All @@ -26,9 +24,6 @@ pluginYml = "0.6.0"
semver = { group = "com.github.zafarkhaja", name = "java-semver", version.ref = "semver" }
paperApi = { group = "io.papermc.paper", name = "paper-api", version.ref = "minecraft" }
bStatsBukkit = { group = "org.bstats", name = "bstats-bukkit", version.ref = "bStats" }
adventureApi = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventureMiniMessage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" }
adventurePlatformBukkit = { group = "net.kyori", name = "adventure-platform-bukkit", version.ref = "adventurePlatformBukkit" }
assertj = { group = "org.assertj", name = "assertj-core", version.ref = "assertj" }
mockitoCore = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
jupiterApi = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jupiter" }
Expand Down
Loading