-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forge20): port commands & tab completer
- Loading branch information
1 parent
18b3438
commit 0043b68
Showing
5 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
forge20/src/main/java/com/envyful/battle/tower/command/BattleTowerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
forge20/src/main/java/com/envyful/battle/tower/command/ReloadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
forge20/src/main/java/com/envyful/battle/tower/command/ResetCooldownCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
forge20/src/main/java/com/envyful/battle/tower/command/ValidateCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
forge20/src/main/java/com/envyful/battle/tower/command/tab/ForgePlayerCompleter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |