small refactoring and added missing async task
This commit is contained in:
parent
bc84b06f0d
commit
125b604393
@ -14,9 +14,7 @@ public class AdminChatCommand extends ApplianceCommand.PlayerChecked<AdminChat>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||||
if(!sender.hasPermission("admin")) {
|
if(!sender.hasPermission("admin")) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = String.join(" ", args);
|
String message = String.join(" ", args);
|
||||||
getAppliance().sendMessage(getPlayer(), message);
|
getAppliance().sendMessage(getPlayer(), message);
|
||||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Playtime extends Appliance {
|
public class Playtime extends Appliance {
|
||||||
public Component getFormattedPlayerTime(OfflinePlayer player){
|
public Component getFormattedPlaytime(OfflinePlayer player) {
|
||||||
int playtimeInTicks = player.getStatistic(Statistic.PLAY_ONE_MINUTE);
|
int playtimeInTicks = player.getStatistic(Statistic.PLAY_ONE_MINUTE);
|
||||||
String playtime = DataSizeConverter.formatSecondsToHumanReadable(playtimeInTicks / Ticks.TICKS_PER_SECOND);
|
String playtime = DataSizeConverter.formatSecondsToHumanReadable(playtimeInTicks / Ticks.TICKS_PER_SECOND);
|
||||||
return Component.text()
|
return Component.text()
|
||||||
@ -24,6 +24,7 @@ public class Playtime extends Appliance {
|
|||||||
.append(Component.text(playtime, NamedTextColor.GOLD))
|
.append(Component.text(playtime, NamedTextColor.GOLD))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||||
return List.of(new PlaytimeCommand());
|
return List.of(new PlaytimeCommand());
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.playtime;
|
package eu.mhsl.craftattack.spawn.appliances.playtime;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.Main;
|
||||||
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
@ -16,16 +17,15 @@ public class PlaytimeCommand extends ApplianceCommand.PlayerChecked<Playtime> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||||
String playerName = getPlayer().getName();
|
String playerName = args.length == 1 ? args[0] : getPlayer().getName();
|
||||||
if(args.length == 1) {
|
|
||||||
playerName = args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(playerName);
|
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
|
||||||
if (!player.hasPlayedBefore()) {
|
OfflinePlayer player = Bukkit.getOfflinePlayer(playerName);
|
||||||
sender.sendMessage(Component.text("Der Spieler existiert nicht!", NamedTextColor.RED));
|
if (!player.hasPlayedBefore()) {
|
||||||
return;
|
sender.sendMessage(Component.text("Der Spieler existiert nicht!", NamedTextColor.RED));
|
||||||
}
|
return;
|
||||||
sender.sendMessage(getAppliance().getFormattedPlayerTime(player));
|
}
|
||||||
|
sender.sendMessage(getAppliance().getFormattedPlaytime(player));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user