small refactoring and added missing async task

This commit is contained in:
Elias Müller 2024-10-20 14:24:12 +02:00
parent bc84b06f0d
commit 125b604393
3 changed files with 13 additions and 14 deletions
src/main/java/eu/mhsl/craftattack/spawn/appliances

@ -14,9 +14,7 @@ public class AdminChatCommand extends ApplianceCommand.PlayerChecked<AdminChat>
@Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
if(!sender.hasPermission("admin")) {
return;
}
if(!sender.hasPermission("admin")) return;
String message = String.join(" ", args);
getAppliance().sendMessage(getPlayer(), message);

@ -14,7 +14,7 @@ import java.util.List;
import java.util.Objects;
public class Playtime extends Appliance {
public Component getFormattedPlayerTime(OfflinePlayer player){
public Component getFormattedPlaytime(OfflinePlayer player) {
int playtimeInTicks = player.getStatistic(Statistic.PLAY_ONE_MINUTE);
String playtime = DataSizeConverter.formatSecondsToHumanReadable(playtimeInTicks / Ticks.TICKS_PER_SECOND);
return Component.text()
@ -24,6 +24,7 @@ public class Playtime extends Appliance {
.append(Component.text(playtime, NamedTextColor.GOLD))
.build();
}
@Override
protected @NotNull List<ApplianceCommand<?>> commands() {
return List.of(new PlaytimeCommand());

@ -1,5 +1,6 @@
package eu.mhsl.craftattack.spawn.appliances.playtime;
import eu.mhsl.craftattack.spawn.Main;
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -16,16 +17,15 @@ public class PlaytimeCommand extends ApplianceCommand.PlayerChecked<Playtime> {
@Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
String playerName = getPlayer().getName();
if(args.length == 1) {
playerName = args[0];
}
String playerName = args.length == 1 ? args[0] : getPlayer().getName();
OfflinePlayer player = Bukkit.getOfflinePlayer(playerName);
if (!player.hasPlayedBefore()) {
sender.sendMessage(Component.text("Der Spieler existiert nicht!", NamedTextColor.RED));
return;
}
sender.sendMessage(getAppliance().getFormattedPlayerTime(player));
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
OfflinePlayer player = Bukkit.getOfflinePlayer(playerName);
if (!player.hasPlayedBefore()) {
sender.sendMessage(Component.text("Der Spieler existiert nicht!", NamedTextColor.RED));
return;
}
sender.sendMessage(getAppliance().getFormattedPlaytime(player));
});
}
}