aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-11-07 17:41:39 +0000
committerLuck <git@lucko.me>2020-11-07 17:41:39 +0000
commit8cc92ff83634dffacfe1f25a135bc9ac665ff68b (patch)
tree35efc9d9131c7ceb1db3822fbb6a0707535f7c18 /spark-bukkit
parent70a468e114316a98f6d7f7e91afa8d50639762c9 (diff)
downloadspark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.tar.gz
spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.tar.bz2
spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.zip
Update from text to adventure
Diffstat (limited to 'spark-bukkit')
-rw-r--r--spark-bukkit/build.gradle6
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java13
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java14
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java33
4 files changed, 37 insertions, 29 deletions
diff --git a/spark-bukkit/build.gradle b/spark-bukkit/build.gradle
index fd5c016..869b16a 100644
--- a/spark-bukkit/build.gradle
+++ b/spark-bukkit/build.gradle
@@ -1,8 +1,8 @@
dependencies {
compile project(':spark-common')
- compile('net.kyori:text-adapter-bukkit:3.0.5') {
- exclude(module: 'text-api')
- exclude(module: 'text-serializer-gson')
+ compile ('net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT') {
+ exclude(module: 'adventure-api')
+ exclude(module: 'adventure-text-serializer-gson')
}
compileOnly 'com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT'
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java
index 5c03289..11f7e9e 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitCommandSender.java
@@ -20,18 +20,21 @@
package me.lucko.spark.bukkit;
-
import me.lucko.spark.common.command.sender.AbstractCommandSender;
-import net.kyori.text.Component;
-import net.kyori.text.adapter.bukkit.TextAdapter;
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.platform.bukkit.BukkitAudiences;
+import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
public class BukkitCommandSender extends AbstractCommandSender<CommandSender> {
- public BukkitCommandSender(CommandSender sender) {
+ private final Audience audience;
+
+ public BukkitCommandSender(CommandSender sender, BukkitAudiences audienceFactory) {
super(sender);
+ this.audience = audienceFactory.sender(sender);
}
@Override
@@ -49,7 +52,7 @@ public class BukkitCommandSender extends AbstractCommandSender<CommandSender> {
@Override
public void sendMessage(Component message) {
- TextAdapter.sendMessage(super.delegate, message);
+ this.audience.sendMessage(message);
}
@Override
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
index 7d749eb..89f6726 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
@@ -28,6 +28,7 @@ import me.lucko.spark.common.platform.PlatformInfo;
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.sampler.tick.TickHook;
import me.lucko.spark.common.sampler.tick.TickReporter;
+import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -39,12 +40,15 @@ import java.util.List;
import java.util.stream.Stream;
public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin {
+ private BukkitAudiences audienceFactory;
+ private SparkPlatform platform;
private CommandExecutor tpsCommand = null;
- private SparkPlatform platform;
@Override
public void onEnable() {
+ this.audienceFactory = BukkitAudiences.create(this);
+
this.platform = new SparkPlatform(this);
this.platform.enable();
@@ -56,7 +60,7 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin {
return true;
}
- BukkitCommandSender s = new BukkitCommandSender(sender) {
+ BukkitCommandSender s = new BukkitCommandSender(sender, this.audienceFactory) {
@Override
public boolean hasPermission(String permission) {
return true;
@@ -88,13 +92,13 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- this.platform.executeCommand(new BukkitCommandSender(sender), args);
+ this.platform.executeCommand(new BukkitCommandSender(sender, this.audienceFactory), args);
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
- return this.platform.tabCompleteCommand(new BukkitCommandSender(sender), args);
+ return this.platform.tabCompleteCommand(new BukkitCommandSender(sender, this.audienceFactory), args);
}
@Override
@@ -117,7 +121,7 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin {
return Stream.concat(
getServer().getOnlinePlayers().stream().filter(player -> player.hasPermission(permission)),
Stream.of(getServer().getConsoleSender())
- ).map(BukkitCommandSender::new);
+ ).map(sender -> new BukkitCommandSender(sender, this.audienceFactory));
}
@Override
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
index ee96630..842ac72 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
@@ -24,8 +24,9 @@ import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.command.modules.HealthModule;
import me.lucko.spark.common.monitor.cpu.CpuMonitor;
import me.lucko.spark.common.monitor.tick.TickStatistics;
-import net.kyori.text.TextComponent;
-import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextComponent;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
enum SparkPlaceholderProvider {
;
@@ -39,11 +40,11 @@ enum SparkPlaceholderProvider {
switch (placeholder) {
case "tps":
- return TextComponent.builder("")
- .append(HealthModule.formatTps(tickStatistics.tps5Sec())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tickStatistics.tps10Sec())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tickStatistics.tps1Min())).append(TextComponent.of(", "))
- .append(HealthModule.formatTps(tickStatistics.tps5Min())).append(TextComponent.of(", "))
+ return Component.text()
+ .append(HealthModule.formatTps(tickStatistics.tps5Sec())).append(Component.text(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps10Sec())).append(Component.text(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps1Min())).append(Component.text(", "))
+ .append(HealthModule.formatTps(tickStatistics.tps5Min())).append(Component.text(", "))
.append(HealthModule.formatTps(tickStatistics.tps15Min()))
.build();
case "tps_5s":
@@ -67,8 +68,8 @@ enum SparkPlaceholderProvider {
switch (placeholder) {
case "tickduration":
- return TextComponent.builder("")
- .append(HealthModule.formatTickDurations(tickStatistics.duration10Sec())).append(TextComponent.of("; "))
+ return Component.text()
+ .append(HealthModule.formatTickDurations(tickStatistics.duration10Sec())).append(Component.text("; "))
.append(HealthModule.formatTickDurations(tickStatistics.duration1Min()))
.build();
case "tickduration_10s":
@@ -81,9 +82,9 @@ enum SparkPlaceholderProvider {
if (placeholder.startsWith("cpu")) {
switch (placeholder) {
case "cpu_system":
- return TextComponent.builder("")
- .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(TextComponent.of(", "))
- .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(TextComponent.of(", "))
+ return Component.text()
+ .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(Component.text(", "))
+ .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(Component.text(", "))
.append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg()))
.build();
case "cpu_system_10s":
@@ -93,9 +94,9 @@ enum SparkPlaceholderProvider {
case "cpu_system_15m":
return HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg());
case "cpu_process":
- return TextComponent.builder("")
- .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(TextComponent.of(", "))
- .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(TextComponent.of(", "))
+ return Component.text()
+ .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(Component.text(", "))
+ .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(Component.text(", "))
.append(HealthModule.formatCpuUsage(CpuMonitor.processLoad15MinAvg()))
.build();
case "cpu_process_10s":
@@ -115,7 +116,7 @@ enum SparkPlaceholderProvider {
if (result == null) {
return null;
}
- return LegacyComponentSerializer.legacy().serialize(result);
+ return LegacyComponentSerializer.legacySection().serialize(result);
}
}