Skip to content

Commit

Permalink
feat(forge20): port commands & tab completer
Browse files Browse the repository at this point in the history
  • Loading branch information
danorris709 committed Aug 30, 2023
1 parent 18b3438 commit 0043b68
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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<Pokemon> 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"));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<String, ForgeEnvyPlayer> {

@Override
public Class<ForgeEnvyPlayer> getSenderClass() {
return ForgeEnvyPlayer.class;
}

@Override
public Class<String> getCompletedClass() {
return String.class;
}

@Override
public List<String> getCompletions(ForgeEnvyPlayer sender, String[] currentData, Annotation... completionData) {
List<String> 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;
}
}

0 comments on commit 0043b68

Please sign in to comment.