diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java index b83624f..ed98c24 100644 --- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java +++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java @@ -11,6 +11,7 @@ import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureMapsCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureTestMapCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.ChallengesRemovePlayerServer; +import de.fanta.challengesjoinentities.commands.ChallengesCommand.ChallengeSetStatsCommand; import de.fanta.challengesjoinentities.commands.ChallengesCommand.ChallengesStatsCommand; import de.fanta.challengesjoinentities.commands.ChallengesCommand.ChallengesloadCommand; import de.fanta.challengesjoinentities.commands.PiglinCommand.AddEntityCommand; @@ -117,6 +118,7 @@ CommandRouter challengesrouter = new CommandRouter(getCommand("challenges")); challengesrouter.addCommandMapping(new ChallengesloadCommand(this), "load"); challengesrouter.addCommandMapping(new ChallengesStatsCommand(plugin.getStatistics()), "stats"); + challengesrouter.addCommandMapping(new ChallengeSetStatsCommand(plugin), "setstats"); CommandRouter adventurerouter = new CommandRouter(getCommand("adventure")); adventurerouter.addCommandMapping(new AdventureLoadCommand(this), "load"); diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeSetStatsCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeSetStatsCommand.java new file mode 100644 index 0000000..9baec66 --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/ChallengesCommand/ChallengeSetStatsCommand.java @@ -0,0 +1,96 @@ +package de.fanta.challengesjoinentities.commands.ChallengesCommand; + +import de.fanta.challengesjoinentities.ChallengesJoinEntities; +import de.fanta.challengesjoinentities.ChatUtil; +import de.iani.cubesidestats.api.StatisticKey; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import de.iani.playerUUIDCache.CachedPlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; + +public class ChallengeSetStatsCommand extends SubCommand { + private final ChallengesJoinEntities plugin; + + public ChallengeSetStatsCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + + if (args.hasNext()) { + String playerString = args.getNext(); + CachedPlayer statsPlayer = plugin.getPlayerUUIDCache().getPlayer(playerString); + if (statsPlayer != null) { + if (args.hasNext()) { + String statsKeyString = args.getNext(); + StatisticKey statisticKey = plugin.getCubesideStatistics().getStatisticKey(statsKeyString, false); + if (statisticKey != null) { + if (args.hasNext()) { + int score; + try { + score = Integer.parseInt(args.getNext()); + } catch (NumberFormatException ex) { + ChatUtil.sendErrorMessage(player, "/challenge setstats "); + return true; + } + if (score > 0) { + plugin.getStatistics().setScore(statsPlayer.getUUID(), statisticKey, score); + ChatUtil.sendNormalMessage(player, "Statistik " + ChatUtil.BLUE + statisticKey.getName() + ChatUtil.GREEN + " von " + ChatUtil.BLUE + statsPlayer.getName() + ChatUtil.GREEN + " wurde auf " + ChatUtil.BLUE + score + ChatUtil.GREEN + " gesetzt!"); + } else { + plugin.getStatistics().deleteScore(statsPlayer.getUUID(), statisticKey); + ChatUtil.sendNormalMessage(player, "Statistik " + ChatUtil.BLUE + statisticKey.getName() + ChatUtil.GREEN + " von " + ChatUtil.BLUE + statsPlayer.getName() + ChatUtil.GREEN + " wurde gelöscht!"); + } + } else { + ChatUtil.sendErrorMessage(player, "/challenge setstats "); + return true; + } + } else { + ChatUtil.sendErrorMessage(player, "StatisticKey nicht gefunden!"); + return true; + } + } else { + ChatUtil.sendErrorMessage(player, "/challenge setstats "); + return true; + } + } else { + ChatUtil.sendErrorMessage(player, ChatUtil.BLUE + playerString + ChatUtil.RED + " nicht gefunden!"); + return true; + } + } else { + ChatUtil.sendErrorMessage(player, "/challenge setstats "); + return true; + } + + + return true; + } + + @Override + public Collection onTabComplete(CommandSender sender, Command command, String alias, ArgsParser args) { + if (args.remaining() == 2) { + Collection keyList = new ArrayList<>(); + for (StatisticKey statisticKey : plugin.getCubesideStatistics().getAllStatisticKeys()) { + if (statisticKey.getName().startsWith("challenge")) { + keyList.add(statisticKey.getName()); + } + } + return keyList; + } + return Collections.emptyList(); + } + + @Override + public String getRequiredPermission() { + return "challenges.stats.edit"; + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/utils/Statistics.java b/src/main/java/de/fanta/challengesjoinentities/utils/Statistics.java index 90ca96b..aab74aa 100644 --- a/src/main/java/de/fanta/challengesjoinentities/utils/Statistics.java +++ b/src/main/java/de/fanta/challengesjoinentities/utils/Statistics.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.function.Consumer; public class Statistics { @@ -159,6 +160,14 @@ }); } + public void setScore(UUID uuid, StatisticKey statisticKey, int score) { + statistics.getStatistics(uuid).setScore(statisticKey, score); + } + + public void deleteScore(UUID uuid, StatisticKey statisticKey) { + statistics.getStatistics(uuid).deleteScore(statisticKey); + } + public void getDataForPositionIfExists(int pos, StatType statType, Consumer callback) { if (pos < 1) { callback.accept(null);