-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ashcon Partovi <[email protected]>
- Loading branch information
Showing
63 changed files
with
1,361 additions
and
403 deletions.
There are no files selected for viewing
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
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
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
41 changes: 41 additions & 0 deletions
41
core/src/main/java/tc/oc/pgm/action/actions/ExposedAction.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,41 @@ | ||
package tc.oc.pgm.action.actions; | ||
|
||
import tc.oc.pgm.action.ActionDefinition; | ||
import tc.oc.pgm.api.feature.Feature; | ||
import tc.oc.pgm.api.match.Match; | ||
import tc.oc.pgm.features.SelfIdentifyingFeatureDefinition; | ||
|
||
/** | ||
* Wraps an action definition to consider it exposed. This is an easy way to avoid needing each | ||
* specialized action to implement a way to expose itself or not. | ||
*/ | ||
public class ExposedAction extends SelfIdentifyingFeatureDefinition | ||
implements ActionDefinition<Match>, Feature<ActionDefinition<? super Match>> { | ||
|
||
private final ActionDefinition<? super Match> delegate; | ||
|
||
public ExposedAction(String id, ActionDefinition<? super Match> delegate) { | ||
super(id); | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public ActionDefinition<? super Match> getDefinition() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public Class<Match> getScope() { | ||
return Match.class; | ||
} | ||
|
||
@Override | ||
public void trigger(Match m) { | ||
delegate.trigger(m); | ||
} | ||
|
||
@Override | ||
public void untrigger(Match m) { | ||
delegate.untrigger(m); | ||
} | ||
} |
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
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
2 changes: 2 additions & 0 deletions
2
core/src/main/java/tc/oc/pgm/api/player/ParticipantState.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package tc.oc.pgm.api.player; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import tc.oc.pgm.api.party.Competitor; | ||
|
||
/** A {@link MatchPlayerState} that exclusively represents a {@link Competitor}. */ | ||
public interface ParticipantState extends MatchPlayerState { | ||
|
||
@Override | ||
@NotNull | ||
Competitor getParty(); | ||
} |
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
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,79 @@ | ||
package tc.oc.pgm.command; | ||
|
||
import static net.kyori.adventure.text.Component.text; | ||
|
||
import cloud.commandframework.annotations.Argument; | ||
import cloud.commandframework.annotations.CommandDescription; | ||
import cloud.commandframework.annotations.CommandMethod; | ||
import cloud.commandframework.annotations.CommandPermission; | ||
import cloud.commandframework.annotations.Flag; | ||
import cloud.commandframework.annotations.specifier.Greedy; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import org.bukkit.command.CommandSender; | ||
import tc.oc.pgm.action.ActionMatchModule; | ||
import tc.oc.pgm.action.actions.ExposedAction; | ||
import tc.oc.pgm.api.Permissions; | ||
import tc.oc.pgm.api.match.Match; | ||
import tc.oc.pgm.util.Audience; | ||
import tc.oc.pgm.util.PrettyPaginatedComponentResults; | ||
import tc.oc.pgm.util.text.TextFormatter; | ||
|
||
@CommandMethod("action|actions") | ||
public class ActionCommand { | ||
|
||
@CommandMethod("list|page [page]") | ||
@CommandDescription("Inspect variables for a player") | ||
@CommandPermission(Permissions.GAMEPLAY) | ||
public void showActions( | ||
Audience audience, | ||
CommandSender sender, | ||
ActionMatchModule amm, | ||
@Argument(value = "page", defaultValue = "1") int page, | ||
@Flag(value = "query", aliases = "q") String query, | ||
@Flag(value = "all", aliases = "a") boolean all) { | ||
|
||
List<ExposedAction> actions = | ||
amm.getExposedActions().stream() | ||
.filter(a -> query == null || a.getId().contains(query)) | ||
.sorted(Comparator.comparing(ExposedAction::getId)) | ||
.collect(Collectors.toList()); | ||
|
||
int resultsPerPage = all ? actions.size() : 8; | ||
int pages = all ? 1 : (actions.size() + resultsPerPage - 1) / resultsPerPage; | ||
|
||
Component title = | ||
TextFormatter.paginate( | ||
text("Actions"), page, pages, NamedTextColor.DARK_AQUA, NamedTextColor.AQUA, true); | ||
Component header = TextFormatter.horizontalLineHeading(sender, title, NamedTextColor.BLUE); | ||
|
||
PrettyPaginatedComponentResults.display( | ||
audience, | ||
actions, | ||
page, | ||
resultsPerPage, | ||
header, | ||
(v, i) -> text((i + 1) + ". ").append(text(v.getId(), NamedTextColor.AQUA))); | ||
} | ||
|
||
@CommandMethod("trigger [action]") | ||
@CommandDescription("Trigger a specific action") | ||
@CommandPermission(Permissions.GAMEPLAY) | ||
public void triggerAction( | ||
Audience audience, Match match, @Argument("action") @Greedy ExposedAction action) { | ||
action.trigger(match); | ||
audience.sendMessage(text("Triggered " + action.getId())); | ||
} | ||
|
||
@CommandMethod("untrigger [action]") | ||
@CommandDescription("Untrigger a specific action") | ||
@CommandPermission(Permissions.GAMEPLAY) | ||
public void untriggerAction( | ||
Audience audience, Match match, @Argument("action") @Greedy ExposedAction action) { | ||
action.untrigger(match); | ||
audience.sendMessage(text("Untriggered " + action.getId())); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
core/src/main/java/tc/oc/pgm/command/parsers/ExposedActionParser.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 tc.oc.pgm.command.parsers; | ||
|
||
import cloud.commandframework.arguments.parser.ParserParameters; | ||
import cloud.commandframework.paper.PaperCommandManager; | ||
import java.util.Collection; | ||
import org.bukkit.command.CommandSender; | ||
import tc.oc.pgm.action.ActionMatchModule; | ||
import tc.oc.pgm.action.actions.ExposedAction; | ||
|
||
public class ExposedActionParser extends MatchObjectParser<ExposedAction, ActionMatchModule> { | ||
|
||
public ExposedActionParser(PaperCommandManager<CommandSender> manager, ParserParameters options) { | ||
super(manager, options, ExposedAction.class, ActionMatchModule.class, "actions"); | ||
} | ||
|
||
@Override | ||
protected Collection<ExposedAction> objects(ActionMatchModule module) { | ||
return module.getExposedActions(); | ||
} | ||
|
||
@Override | ||
protected String getName(ExposedAction obj) { | ||
return obj.getId(); | ||
} | ||
} |
Oops, something went wrong.