From 0043b6827ad68afbb0f67d6905520d31254abfc5 Mon Sep 17 00:00:00 2001 From: Daniel Norris Date: Wed, 30 Aug 2023 09:24:12 +0100 Subject: [PATCH] feat(forge20): port commands & tab completer --- .../tower/command/BattleTowerCommand.java | 34 ++++++++++++++ .../battle/tower/command/ReloadCommand.java | 25 ++++++++++ .../tower/command/ResetCooldownCommand.java | 38 +++++++++++++++ .../battle/tower/command/ValidateCommand.java | 46 +++++++++++++++++++ .../command/tab/ForgePlayerCompleter.java | 40 ++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 forge20/src/main/java/com/envyful/battle/tower/command/BattleTowerCommand.java create mode 100644 forge20/src/main/java/com/envyful/battle/tower/command/ReloadCommand.java create mode 100644 forge20/src/main/java/com/envyful/battle/tower/command/ResetCooldownCommand.java create mode 100644 forge20/src/main/java/com/envyful/battle/tower/command/ValidateCommand.java create mode 100644 forge20/src/main/java/com/envyful/battle/tower/command/tab/ForgePlayerCompleter.java diff --git a/forge20/src/main/java/com/envyful/battle/tower/command/BattleTowerCommand.java b/forge20/src/main/java/com/envyful/battle/tower/command/BattleTowerCommand.java new file mode 100644 index 0000000..2b6fd13 --- /dev/null +++ b/forge20/src/main/java/com/envyful/battle/tower/command/BattleTowerCommand.java @@ -0,0 +1,34 @@ +package com.envyful.battle.tower.command; + +import com.envyful.api.command.annotate.Command; +import com.envyful.api.command.annotate.Permissible; +import com.envyful.api.command.annotate.SubCommands; +import com.envyful.api.command.annotate.executor.CommandProcessor; +import com.envyful.api.command.annotate.executor.Sender; +import com.envyful.battle.tower.EnvyBattleTower; +import com.envyful.battle.tower.gui.BattleTowerUI; +import com.pixelmonmod.pixelmon.api.storage.StorageProxy; +import net.minecraft.server.level.ServerPlayer; + +@Command( + value = "envybattletower", + description = "Battle tower command", + aliases = { + "battletower", + "ebattletower", + "bt" + } +) +@Permissible("com.envyful.battle.tower.command") +@SubCommands({ReloadCommand.class, ValidateCommand.class, ResetCooldownCommand.class}) +public class BattleTowerCommand { + + @CommandProcessor + public void onCommand(@Sender ServerPlayer sender) { + if (StorageProxy.getParty(sender).guiOpened) { + return; + } + + BattleTowerUI.open(EnvyBattleTower.getInstance().getPlayerManager().getPlayer(sender)); + } +} diff --git a/forge20/src/main/java/com/envyful/battle/tower/command/ReloadCommand.java b/forge20/src/main/java/com/envyful/battle/tower/command/ReloadCommand.java new file mode 100644 index 0000000..9835489 --- /dev/null +++ b/forge20/src/main/java/com/envyful/battle/tower/command/ReloadCommand.java @@ -0,0 +1,25 @@ +package com.envyful.battle.tower.command; + +import com.envyful.api.command.annotate.Child; +import com.envyful.api.command.annotate.Command; +import com.envyful.api.command.annotate.Permissible; +import com.envyful.api.command.annotate.executor.CommandProcessor; +import com.envyful.api.command.annotate.executor.Sender; +import com.envyful.api.forge.chat.UtilChatColour; +import com.envyful.battle.tower.EnvyBattleTower; +import net.minecraft.commands.CommandSource; + +@Command( + value = "reload", + description = "Reloads configs" +) +@Permissible("com.envyful.battle.tower.command.reload") +@Child +public class ReloadCommand { + + @CommandProcessor + public void onCommand(@Sender CommandSource sender) { + EnvyBattleTower.getInstance().reloadConfig(); + sender.sendSystemMessage(UtilChatColour.colour("&a&l(!) &aReloaded")); + } +} diff --git a/forge20/src/main/java/com/envyful/battle/tower/command/ResetCooldownCommand.java b/forge20/src/main/java/com/envyful/battle/tower/command/ResetCooldownCommand.java new file mode 100644 index 0000000..642e2ab --- /dev/null +++ b/forge20/src/main/java/com/envyful/battle/tower/command/ResetCooldownCommand.java @@ -0,0 +1,38 @@ +package com.envyful.battle.tower.command; + +import com.envyful.api.command.annotate.Child; +import com.envyful.api.command.annotate.Command; +import com.envyful.api.command.annotate.Permissible; +import com.envyful.api.command.annotate.executor.Argument; +import com.envyful.api.command.annotate.executor.CommandProcessor; +import com.envyful.api.command.annotate.executor.Completable; +import com.envyful.api.command.annotate.executor.Sender; +import com.envyful.api.forge.chat.UtilChatColour; +import com.envyful.api.forge.player.ForgeEnvyPlayer; +import com.envyful.battle.tower.EnvyBattleTower; +import com.envyful.battle.tower.command.tab.ForgePlayerCompleter; +import com.envyful.battle.tower.player.BattleTowerAttribute; +import net.minecraft.commands.CommandSource; + +@Command( + value = "resetcooldown", + description = "Resets the cooldown for a player" +) +@Permissible("com.envyful.battle.tower.command.resetcooldown") +@Child +public class ResetCooldownCommand { + + @CommandProcessor + public void onCommand(@Sender CommandSource sender, + @Completable(ForgePlayerCompleter.class) @Argument ForgeEnvyPlayer target) { + BattleTowerAttribute attribute = target.getAttribute(EnvyBattleTower.class); + + if (attribute == null) { + sender.sendSystemMessage(UtilChatColour.colour("Failed to reset cooldown for " + target.getName() + " please try again in a minute!")); + return; + } + + attribute.setLastAttempt(new BattleTowerAttribute.AttemptDetails(0, 0, 0)); + sender.sendSystemMessage(UtilChatColour.colour("Cooldown reset for " + target.getName())); + } +} diff --git a/forge20/src/main/java/com/envyful/battle/tower/command/ValidateCommand.java b/forge20/src/main/java/com/envyful/battle/tower/command/ValidateCommand.java new file mode 100644 index 0000000..5687f76 --- /dev/null +++ b/forge20/src/main/java/com/envyful/battle/tower/command/ValidateCommand.java @@ -0,0 +1,46 @@ +package com.envyful.battle.tower.command; + +import com.envyful.api.command.annotate.Child; +import com.envyful.api.command.annotate.Command; +import com.envyful.api.command.annotate.Permissible; +import com.envyful.api.command.annotate.executor.CommandProcessor; +import com.envyful.api.command.annotate.executor.Sender; +import com.envyful.api.forge.chat.UtilChatColour; +import com.envyful.battle.tower.EnvyBattleTower; +import com.envyful.battle.tower.config.BattleTowerConfig; +import com.pixelmonmod.pixelmon.api.pokemon.Pokemon; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.server.level.ServerPlayer; + +import java.util.List; + +@Command( + value = "validate", + description = "Validates the pokepastes" +) +@Permissible("com.envyful.battle.tower.command.validate") +@Child +public class ValidateCommand { + + @CommandProcessor + public void onCommand(@Sender ServerPlayer sender) { + boolean found = false; + + for (BattleTowerConfig.TeamPossibilities teamPossibility : EnvyBattleTower.getInstance().getConfig().getTeamPossibilities()) { + for (BattleTowerConfig.PokePaste pokePaste : teamPossibility.getTeams().getWeightedSet().keySet()) { + List team = pokePaste.getTeam(); + + if (team == null || team.isEmpty()) { + found = true; + sender.sendSystemMessage(UtilChatColour.colour("&e&l(!) &eFound invalid team for " + + pokePaste.getPaste()).copy() + .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, pokePaste.getPaste())))); + } + } + } + + if (!found) { + sender.sendSystemMessage(UtilChatColour.colour("&e&l(!) &eNo invalid pastes found")); + } + } +} diff --git a/forge20/src/main/java/com/envyful/battle/tower/command/tab/ForgePlayerCompleter.java b/forge20/src/main/java/com/envyful/battle/tower/command/tab/ForgePlayerCompleter.java new file mode 100644 index 0000000..cb8ac5d --- /dev/null +++ b/forge20/src/main/java/com/envyful/battle/tower/command/tab/ForgePlayerCompleter.java @@ -0,0 +1,40 @@ +package com.envyful.battle.tower.command.tab; + +import com.envyful.api.command.injector.TabCompleter; +import com.envyful.api.forge.command.completion.player.ExcludeSelfCompletion; +import com.envyful.api.forge.player.ForgeEnvyPlayer; +import com.google.common.collect.Lists; +import net.minecraftforge.server.ServerLifecycleHooks; + +import java.lang.annotation.Annotation; +import java.util.List; + +public class ForgePlayerCompleter implements TabCompleter { + + @Override + public Class getSenderClass() { + return ForgeEnvyPlayer.class; + } + + @Override + public Class getCompletedClass() { + return String.class; + } + + @Override + public List getCompletions(ForgeEnvyPlayer sender, String[] currentData, Annotation... completionData) { + List playerNames = Lists.newArrayList(); + + for (var player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers()) { + if (completionData.length < 1 || completionData[0] instanceof ExcludeSelfCompletion) { + if (player.getName().equals(sender.getName())) { + continue; + } + } + + playerNames.add(player.getName().getString()); + } + + return playerNames; + } +}