Skip to content

Commit c72bd9d

Browse files
committed
update plugin
1 parent 3d65aa6 commit c72bd9d

19 files changed

+235
-249
lines changed

build.gradle.kts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
plugins {
22
java
3-
id("com.github.johnrengelman.shadow") version "8.1.1"
4-
id("xyz.jpenilla.run-paper") version "2.2.3"
3+
id("com.gradleup.shadow") version ("8.3.2")
4+
id("xyz.jpenilla.run-paper") version ("2.3.1")
55
}
66

77
group = "me.xginko.betterworldstats"
8-
version = "1.10.2"
8+
version = "1.11.0"
99
description = "Show stats about server age, map size and unique player joins on your minecraft server."
10-
java.sourceCompatibility = JavaVersion.VERSION_1_8
11-
java.targetCompatibility = JavaVersion.VERSION_1_8
1210

1311
repositories {
1412
mavenCentral()
@@ -27,15 +25,16 @@ repositories {
2725
}
2826

2927
dependencies {
30-
compileOnly("org.jetbrains:annotations:24.1.0")
3128
compileOnly("com.destroystokyo.paper:paper-api:1.12.2-R0.1-SNAPSHOT")
3229
compileOnly("me.clip:placeholderapi:2.11.5")
30+
compileOnly("org.jetbrains:annotations:24.1.0")
3331

34-
implementation("net.kyori:adventure-platform-bukkit:4.3.2")
35-
implementation("net.kyori:adventure-text-minimessage:4.16.0")
36-
implementation("net.kyori:adventure-text-serializer-ansi:4.16.0")
37-
implementation("net.kyori:adventure-text-serializer-legacy:4.16.0")
38-
implementation("net.kyori:adventure-text-logger-slf4j:4.16.0")
32+
implementation("net.kyori:adventure-api:4.17.0")
33+
implementation("net.kyori:adventure-text-minimessage:4.17.0")
34+
implementation("net.kyori:adventure-text-serializer-ansi:4.17.0")
35+
implementation("net.kyori:adventure-text-serializer-legacy:4.17.0")
36+
implementation("net.kyori:adventure-text-logger-slf4j:4.17.0")
37+
implementation("net.kyori:adventure-platform-bukkit:4.3.4")
3938

4039
implementation("io.papermc:paperlib:1.0.8")
4140
implementation("org.bstats:bstats-bukkit:3.0.2")
@@ -45,9 +44,13 @@ dependencies {
4544

4645
runPaper.folia.registerTask();
4746

47+
java.toolchain {
48+
languageVersion = JavaLanguageVersion.of(8)
49+
}
50+
4851
tasks {
4952
runServer {
50-
minecraftVersion("1.20.4")
53+
minecraftVersion("1.20.6")
5154
}
5255

5356
compileJava {

src/main/java/me/xginko/betterworldstats/BetterWorldStats.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import me.xginko.betterworldstats.config.Config;
55
import me.xginko.betterworldstats.config.LanguageCache;
66
import me.xginko.betterworldstats.hooks.BWSHook;
7-
import me.xginko.betterworldstats.utils.KyoriUtil;
7+
import me.xginko.betterworldstats.utils.Util;
8+
import net.kyori.adventure.identity.Identity;
89
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
910
import net.kyori.adventure.text.Component;
1011
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
@@ -36,41 +37,37 @@ public final class BetterWorldStats extends JavaPlugin {
3637
@Override
3738
public void onEnable() {
3839
instance = this;
39-
audiences = BukkitAudiences.create(this);
40+
audiences = BukkitAudiences.create(instance);
4041
logger = ComponentLogger.logger(getLogger().getName());
41-
bStats = new Metrics(this, 17204);
42-
43-
logger.info(Component.text(" ").style(KyoriUtil.GUPPIE_GREEN_BOLD));
44-
logger.info(Component.text(" ___ _ _ ").style(KyoriUtil.GUPPIE_GREEN_BOLD));
45-
logger.info(Component.text(" | _ ) ___| |_| |_ ___ _ _ ").style(KyoriUtil.GUPPIE_GREEN_BOLD));
46-
logger.info(Component.text(" | _ \\/ -_) _| _/ -_) '_| ").style(KyoriUtil.GUPPIE_GREEN_BOLD));
47-
logger.info(Component.text(" __|___/\\___|\\__|\\__\\___|_|_ _ _ ").style(KyoriUtil.GUPPIE_GREEN_BOLD));
48-
logger.info(Component.text(" \\ \\ / /__ _ _| |__| / __| |_ __ _| |_ ___").style(KyoriUtil.GUPPIE_GREEN_BOLD));
49-
logger.info(Component.text(" \\ \\/\\/ / _ \\ '_| / _` \\__ \\ _/ _` | _(_-<").style(KyoriUtil.GUPPIE_GREEN_BOLD));
50-
logger.info(Component.text(" \\_/\\_/\\___/_| |_\\__,_|___/\\__\\__,_|\\__/__/").style(KyoriUtil.GUPPIE_GREEN_BOLD));
51-
logger.info(Component.text(" ").style(KyoriUtil.GUPPIE_GREEN_BOLD));
52-
53-
try {
54-
getDataFolder().mkdirs();
55-
} catch (Throwable t) {
56-
logger.error("Failed to create plugin folder!", t);
57-
getServer().getPluginManager().disablePlugin(this);
58-
}
59-
60-
logger.info("Loading languages");
42+
bStats = new Metrics(instance, 17204);
43+
44+
logger.info(Component.text(" ").style(Util.GUPPIE_GREEN_BOLD));
45+
logger.info(Component.text(" ___ _ _ ").style(Util.GUPPIE_GREEN_BOLD));
46+
logger.info(Component.text(" | _ ) ___| |_| |_ ___ _ _ ").style(Util.GUPPIE_GREEN_BOLD));
47+
logger.info(Component.text(" | _ \\/ -_) _| _/ -_) '_| ").style(Util.GUPPIE_GREEN_BOLD));
48+
logger.info(Component.text(" __|___/\\___|\\__|\\__\\___|_|_ _ _ ").style(Util.GUPPIE_GREEN_BOLD));
49+
logger.info(Component.text(" \\ \\ / /__ _ _| |__| / __| |_ __ _| |_ ___").style(Util.GUPPIE_GREEN_BOLD));
50+
logger.info(Component.text(" \\ \\/\\/ / _ \\ '_| / _` \\__ \\ _/ _` | _(_-<").style(Util.GUPPIE_GREEN_BOLD));
51+
logger.info(Component.text(" \\_/\\_/\\___/_| |_\\__,_|___/\\__\\__,_|\\__/__/").style(Util.GUPPIE_GREEN_BOLD));
52+
logger.info(Component.text(" ").style(Util.GUPPIE_GREEN_BOLD));
53+
54+
logger.info("Loading translations");
6155
reloadLang();
56+
6257
logger.info("Loading config");
6358
reloadConfiguration();
59+
6460
logger.info("Registering commands");
6561
BWSCmd.reloadCommands();
62+
6663
logger.info("Done.");
6764
}
6865

6966
@Override
7067
public void onDisable() {
7168
BWSHook.HOOKS.forEach(BWSHook::unHook);
7269
if (statistics != null) {
73-
statistics.shutdown();
70+
statistics.disable();
7471
statistics = null;
7572
}
7673
if (audiences != null) {
@@ -91,19 +88,19 @@ public void onDisable() {
9188
return instance;
9289
}
9390

94-
public static @NotNull Statistics getStatistics() {
91+
public static @NotNull Statistics statistics() {
9592
return statistics;
9693
}
9794

98-
public static @NotNull BukkitAudiences getAudiences() {
95+
public static @NotNull BukkitAudiences audiences() {
9996
return audiences;
10097
}
10198

102-
public static @NotNull Config getConfiguration() {
99+
public static @NotNull Config config() {
103100
return config;
104101
}
105102

106-
public static @NotNull ComponentLogger getLog() {
103+
public static @NotNull ComponentLogger logger() {
107104
return logger;
108105
}
109106

@@ -112,7 +109,7 @@ public void onDisable() {
112109
}
113110

114111
public static @NotNull LanguageCache getLang(CommandSender commandSender) {
115-
return getLang(KyoriUtil.getLocale(commandSender));
112+
return getLang(audiences.sender(commandSender).pointers().get(Identity.LOCALE).orElse(config.default_lang));
116113
}
117114

118115
public static @NotNull LanguageCache getLang(String lang) {
@@ -129,7 +126,7 @@ public void reloadPlugin() {
129126
private void reloadConfiguration() {
130127
try {
131128
if (statistics != null)
132-
statistics.shutdown();
129+
statistics.disable();
133130
config = new Config();
134131
statistics = new Statistics();
135132
BWSHook.reloadHooks();
@@ -143,7 +140,7 @@ public void reloadLang() {
143140
languageCacheMap = new HashMap<>();
144141
try {
145142
for (String localeString : getAvailableTranslations()) {
146-
logger.info("Found language file for " + localeString);
143+
logger.info("Found language file for {}", localeString);
147144
languageCacheMap.put(localeString, new LanguageCache(localeString));
148145
}
149146
} catch (Throwable t) {
@@ -153,7 +150,7 @@ public void reloadLang() {
153150
logger.error("Unable to load translations. Disabling.");
154151
getServer().getPluginManager().disablePlugin(this);
155152
} else {
156-
logger.info("Loaded " + languageCacheMap.size() + " translations");
153+
logger.info("Loaded {} translations", languageCacheMap.size());
157154
}
158155
}
159156
}

src/main/java/me/xginko/betterworldstats/Statistics.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import me.xginko.betterworldstats.stats.WorldStats;
44
import me.xginko.betterworldstats.stats.BirthCalendar;
55
import me.xginko.betterworldstats.stats.PlayerStats;
6+
import me.xginko.betterworldstats.utils.Disableable;
67
import org.jetbrains.annotations.NotNull;
78

8-
public final class Statistics {
9+
import java.util.concurrent.CompletableFuture;
10+
11+
public final class Statistics implements Disableable {
912

1013
public final @NotNull BirthCalendar birthCalendar;
1114
public final @NotNull WorldStats worldStats;
@@ -17,7 +20,12 @@ public Statistics() {
1720
this.playerStats = new PlayerStats();
1821
}
1922

20-
public void shutdown() {
23+
@Override
24+
public void disable() {
2125
playerStats.disable();
2226
}
27+
28+
public CompletableFuture<Statistics> get() {
29+
return worldStats.get().thenApply(stats -> this);
30+
}
2331
}

src/main/java/me/xginko/betterworldstats/utils/ComponentLoggerProviderImpl.java renamed to src/main/java/me/xginko/betterworldstats/adventure/ComponentLoggerProviderImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package me.xginko.betterworldstats.utils;
1+
package me.xginko.betterworldstats.adventure;
22

3+
import me.xginko.betterworldstats.utils.TranslatableMapper;
34
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
45
import net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider;
56
import net.kyori.adventure.text.serializer.ansi.ANSIComponentSerializer;
@@ -8,6 +9,7 @@
89

910
@SuppressWarnings("UnstableApiUsage")
1011
public final class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
12+
1113
private static final @NotNull ANSIComponentSerializer SERIALIZER = ANSIComponentSerializer.builder()
1214
.flattener(TranslatableMapper.FLATTENER)
1315
.build();

src/main/java/me/xginko/betterworldstats/commands/betterworldstats/BetterWorldStatsCmd.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import me.xginko.betterworldstats.commands.SubCmd;
55
import me.xginko.betterworldstats.commands.betterworldstats.subcommands.ReloadSubCmd;
66
import me.xginko.betterworldstats.commands.betterworldstats.subcommands.VersionSubCmd;
7-
import me.xginko.betterworldstats.utils.KyoriUtil;
7+
import me.xginko.betterworldstats.utils.Util;
88
import net.kyori.adventure.text.Component;
99
import net.kyori.adventure.text.format.NamedTextColor;
1010
import org.bukkit.command.Command;
@@ -57,11 +57,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
5757
}
5858

5959
private void sendCommandOverview(CommandSender sender) {
60-
KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(KyoriUtil.GUPPIE_GREEN));
61-
KyoriUtil.sendMessage(sender, Component.text("BetterWorldStats Commands").color(KyoriUtil.GUPPIE_GREEN));
62-
KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(KyoriUtil.GUPPIE_GREEN));
63-
for (SubCmd subCmd : subCmds) KyoriUtil.sendMessage(sender,
60+
Util.sendMessage(sender, Component.text("-----------------------------------------------------").color(Util.GUPPIE_GREEN));
61+
Util.sendMessage(sender, Component.text("BetterWorldStats Commands").color(Util.GUPPIE_GREEN));
62+
Util.sendMessage(sender, Component.text("-----------------------------------------------------").color(Util.GUPPIE_GREEN));
63+
for (SubCmd subCmd : subCmds) Util.sendMessage(sender,
6464
subCmd.getSyntax().append(Component.text(" - ").color(NamedTextColor.DARK_GRAY)).append(subCmd.getDescription()));
65-
KyoriUtil.sendMessage(sender, Component.text("-----------------------------------------------------").color(KyoriUtil.GUPPIE_GREEN));
65+
Util.sendMessage(sender, Component.text("-----------------------------------------------------").color(Util.GUPPIE_GREEN));
6666
}
6767
}

src/main/java/me/xginko/betterworldstats/commands/betterworldstats/subcommands/ReloadSubCmd.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import me.xginko.betterworldstats.BetterWorldStats;
44
import me.xginko.betterworldstats.commands.SubCmd;
5-
import me.xginko.betterworldstats.utils.KyoriUtil;
5+
import me.xginko.betterworldstats.utils.Util;
66
import net.kyori.adventure.text.Component;
77
import net.kyori.adventure.text.TextComponent;
88
import net.kyori.adventure.text.format.NamedTextColor;
99
import org.bukkit.command.CommandSender;
1010

11+
import java.util.concurrent.CompletableFuture;
12+
1113
public class ReloadSubCmd extends SubCmd {
1214

1315
public ReloadSubCmd() {}
@@ -24,18 +26,20 @@ public TextComponent getDescription() {
2426

2527
@Override
2628
public TextComponent getSyntax() {
27-
return Component.text("/bws reload").color(KyoriUtil.GUPPIE_GREEN);
29+
return Component.text("/bws reload").color(Util.GUPPIE_GREEN);
2830
}
2931

3032
@Override
3133
public void perform(CommandSender sender, String[] args) {
3234
if (!sender.hasPermission("betterworldstats.reload")) {
33-
KyoriUtil.sendMessage(sender, BetterWorldStats.getLang(sender).noPermissionMsg(sender));
35+
Util.sendMessage(sender, BetterWorldStats.getLang(sender).noPermissionMsg(sender));
3436
return;
3537
}
3638

37-
KyoriUtil.sendMessage(sender, Component.text("Reloading BetterWorldStats...").color(NamedTextColor.WHITE));
38-
BetterWorldStats.getInstance().reloadPlugin();
39-
KyoriUtil.sendMessage(sender, Component.text("Reload complete.").color(NamedTextColor.GREEN));
39+
Util.sendMessage(sender, Component.text("Reloading BetterWorldStats...").color(NamedTextColor.WHITE));
40+
CompletableFuture.runAsync(() -> {
41+
BetterWorldStats.getInstance().reloadPlugin();
42+
Util.sendMessage(sender, Component.text("Reload complete.").color(NamedTextColor.GREEN));
43+
});
4044
}
4145
}

src/main/java/me/xginko/betterworldstats/commands/betterworldstats/subcommands/VersionSubCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import me.xginko.betterworldstats.BetterWorldStats;
44
import me.xginko.betterworldstats.commands.SubCmd;
5-
import me.xginko.betterworldstats.utils.KyoriUtil;
5+
import me.xginko.betterworldstats.utils.Util;
66
import net.kyori.adventure.text.Component;
77
import net.kyori.adventure.text.TextComponent;
88
import net.kyori.adventure.text.event.ClickEvent;
@@ -26,19 +26,19 @@ public TextComponent getDescription() {
2626

2727
@Override
2828
public TextComponent getSyntax() {
29-
return Component.text("/bws version").color(KyoriUtil.GUPPIE_GREEN);
29+
return Component.text("/bws version").color(Util.GUPPIE_GREEN);
3030
}
3131

3232
@Override
3333
public void perform(CommandSender sender, String[] args) {
3434
if (!sender.hasPermission("betterworldstats.version")) {
35-
KyoriUtil.sendMessage(sender, BetterWorldStats.getLang(sender).noPermissionMsg(sender));
35+
Util.sendMessage(sender, BetterWorldStats.getLang(sender).noPermissionMsg(sender));
3636
return;
3737
}
3838

3939
final PluginDescriptionFile pluginYML = BetterWorldStats.getInstance().getDescription();
4040

41-
KyoriUtil.sendMessage(sender, Component.newline()
41+
Util.sendMessage(sender, Component.newline()
4242
.append(
4343
Component.text(pluginYML.getName() + " " + pluginYML.getVersion())
4444
.color(NamedTextColor.GOLD)

0 commit comments

Comments
 (0)