Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite/command api #696

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
83cb87d
Move Command registration to its own function
Intybyte Aug 20, 2024
91bd35c
Add New API Dependency
Intybyte Aug 20, 2024
ed6ee20
MovecraftCommand adapted to new API
Intybyte Aug 20, 2024
711020f
Shade aikar's ACF
Intybyte Aug 20, 2024
fe417e9
Add description to MovecraftCommand
Intybyte Aug 20, 2024
8c5b9ae
Shade attempt 2
Intybyte Aug 20, 2024
02abbc3
Update command description
Intybyte Aug 21, 2024
cf7d288
Add CraftInfoCommand
Intybyte Aug 21, 2024
c2924ad
Forgot this
Intybyte Aug 21, 2024
2290436
Add CraftReportCommand
Intybyte Aug 21, 2024
3f3d00c
Add CraftTypeCommand pt1
Intybyte Aug 21, 2024
5ee2fad
Add CraftTypeCommand pt2
Intybyte Aug 21, 2024
f59cc64
This wasn't needed
Intybyte Aug 21, 2024
e14dd75
Small change to CraftReportCommand
Intybyte Aug 21, 2024
76a2385
Apply similar changes to CraftInfoCommand
Intybyte Aug 21, 2024
ee05772
Add CruiseCommand pt1
Intybyte Aug 21, 2024
91398c7
Add CruiseCommand pt2
Intybyte Aug 21, 2024
911aa4d
Add CruiseDirection resolver for ACF
Intybyte Aug 21, 2024
1099193
Add CruiseCommand pt3
Intybyte Aug 21, 2024
c4efaf2
Made custom command manager to handle or operations
Intybyte Aug 21, 2024
c669efd
Fix permissions
Intybyte Aug 21, 2024
cf865db
Fix CruiseCommand
Intybyte Aug 21, 2024
ad84cc8
Change to yawLocationCruising
Intybyte Aug 21, 2024
8171ade
Add CraftType context resolver
Intybyte Aug 22, 2024
27b9b8b
Use string parsing
Intybyte Aug 24, 2024
6038679
byebye self
Intybyte Aug 24, 2024
aa6716c
Simplify
Intybyte Aug 24, 2024
72c8843
Simplified Permission check
Intybyte Aug 24, 2024
a254a3a
Permission fixes
Intybyte Aug 25, 2024
c3c7922
Move into command manager
Intybyte Aug 31, 2024
a11c331
Merge remote-tracking branch 'origin/main' into rewrite/commandAPI
Intybyte Aug 31, 2024
2814463
Fixing craftInfo, this requires either restoring self or reverting
Intybyte Aug 31, 2024
0ea58e8
@PreCommand works with inverted logic
Intybyte Aug 31, 2024
fd8ab3b
Remove "self" from CraftInfoCommand
Intybyte Sep 3, 2024
f81e45b
Remove "self" from CraftTypeCommand
Intybyte Sep 3, 2024
a984656
Add ManOverboardCommand
Intybyte Sep 3, 2024
16d3af8
Add PilotCommand pt1
Intybyte Sep 3, 2024
bd710bd
Add PilotCommand pt2
Intybyte Sep 3, 2024
2f76c8d
Add ReleaseCommand pt1
Intybyte Sep 3, 2024
105d21c
Add ReleaseCommand pt2
Intybyte Sep 3, 2024
9284708
Add RotateCommand pt1
Intybyte Sep 3, 2024
f5995c8
Add RotateCommand pt2
Intybyte Sep 3, 2024
bb6f576
Add ScuttleCommand
Intybyte Sep 3, 2024
38aa24e
Merge branch 'refs/heads/main' into rewrite/commandAPI
Intybyte Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Movecraft/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
runtimeOnly(project(":movecraft-v1_21", "reobf"))
implementation(project(":movecraft-api"))
compileOnly("org.yaml:snakeyaml:2.0")
implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT")
}

tasks.shadowJar {
Expand All @@ -25,7 +26,11 @@ tasks.shadowJar {
include(project(":movecraft-v1_18"))
include(project(":movecraft-v1_20"))
include(project(":movecraft-v1_21"))
include(dependency("co.aikar:acf-paper:0.5.1-SNAPSHOT"))
}

relocate("co.aikar.commands", "Movecraft.acf")
relocate("co.aikar.locales", "Movecraft.locales")
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
}

tasks.processResources {
Expand Down
27 changes: 16 additions & 11 deletions Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.countercraft.movecraft.config.Settings;
import net.countercraft.movecraft.craft.ChunkManager;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.datatag.CraftDataTagRegistry;
import net.countercraft.movecraft.features.contacts.ContactsCommand;
import net.countercraft.movecraft.features.contacts.ContactsManager;
import net.countercraft.movecraft.features.contacts.ContactsSign;
Expand Down Expand Up @@ -198,16 +197,7 @@ public void onEnable() {

getServer().getPluginManager().registerEvents(new InteractListener(), this);

getCommand("movecraft").setExecutor(new MovecraftCommand());
getCommand("release").setExecutor(new ReleaseCommand());
getCommand("pilot").setExecutor(new PilotCommand());
getCommand("rotate").setExecutor(new RotateCommand());
getCommand("cruise").setExecutor(new CruiseCommand());
getCommand("craftreport").setExecutor(new CraftReportCommand());
getCommand("manoverboard").setExecutor(new ManOverboardCommand());
getCommand("scuttle").setExecutor(new ScuttleCommand());
getCommand("crafttype").setExecutor(new CraftTypeCommand());
getCommand("craftinfo").setExecutor(new CraftInfoCommand());
initializeCommands();

getServer().getPluginManager().registerEvents(new BlockListener(), this);
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
Expand Down Expand Up @@ -244,6 +234,21 @@ public void onEnable() {
logger.info("[V " + getDescription().getVersion() + "] has been enabled.");
}

private void initializeCommands() {
MovecraftCommandManager movecraftCommandManager = new MovecraftCommandManager(this);

movecraftCommandManager.registerCommand(new MovecraftCommand());
movecraftCommandManager.registerCommand(new CraftInfoCommand());
movecraftCommandManager.registerCommand(new CraftReportCommand());
movecraftCommandManager.registerCommand(new CraftTypeCommand());
movecraftCommandManager.registerCommand(new CruiseCommand());
movecraftCommandManager.registerCommand(new ManOverboardCommand());
movecraftCommandManager.registerCommand(new PilotCommand());
movecraftCommandManager.registerCommand(new ReleaseCommand());
movecraftCommandManager.registerCommand(new RotateCommand());
movecraftCommandManager.registerCommand(new ScuttleCommand());
}

@Override
public void onLoad() {
super.onLoad();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package net.countercraft.movecraft.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.InvalidCommandArgument;
import co.aikar.commands.annotation.*;
import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.util.MathUtils;
import net.countercraft.movecraft.util.TopicPaginator;
import org.bukkit.command.Command;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
import java.util.function.Function;

public class CraftInfoCommand implements TabExecutor {
@CommandAlias("craftinfo")
public class CraftInfoCommand extends BaseCommand {
private static final List<Function<Craft,? extends Iterable<String>>> providers = new ArrayList<>();
static {
registerMultiProvider(CraftInfoCommand::allowedBlockProvider);
Expand Down Expand Up @@ -48,51 +49,48 @@ public static void registerProvider(@NotNull Function<Craft, String> provider){
providers.add(provider.andThen(List::of));
}

@Default
@Syntax("[player] <page>")
@Description("Get information on a piloted craft")
@CommandCompletion("@players")
public static void onOtherPlayer(CommandSender commandSender, String[] args) {
if (args.length > 2) {
throw new InvalidCommandArgument("Max allowed arguments: 2");
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(args.length == 0){
if (!(sender instanceof Player)){
sender.sendMessage("Supply a parameter.");
return true;
try {
int page = args.length == 0 ? 1 : Integer.parseInt(args[0]);
if (!(commandSender instanceof Player player)) {
commandSender.sendMessage("You can't run this command on yourself as console");
return;
}
Craft craft = CraftManager.getInstance().getCraftByPlayer(((Player) sender));
if(craft == null){
sender.sendMessage("You must be piloting a craft.");
return true;

Craft craft = CraftManager.getInstance().getCraftByPlayer(player);
if (craft == null) {
commandSender.sendMessage("No player craft found");
return;
}
craftInfo(sender, craft, 1);
return true;
}
OptionalInt pageQuery;
if (sender instanceof Player && (pageQuery = MathUtils.parseInt(args[0])).isPresent()){
Craft craft = CraftManager.getInstance().getCraftByPlayer(((Player) sender));
if(craft == null){
sender.sendMessage("You must be piloting a craft.");
return true;

craftInfo(commandSender, craft, page);

} catch (NumberFormatException e) {
Player playerSubject = Bukkit.getPlayer(args[0]);
if (playerSubject == null) {
commandSender.sendMessage("First argument must be either a number or a player");
return;
}
craftInfo(sender, craft, pageQuery.getAsInt());
return true;
}
var craft = CraftManager.getInstance().getCraftByPlayerName(args[0]);
if (craft == null) {
sender.sendMessage("No player found");
return true;
}
if(args.length > 1){
pageQuery = MathUtils.parseInt(args[1]);
if(pageQuery.isEmpty()){
sender.sendMessage("Parameter " + args[1] + " must be a page number.");
return true;

Craft craft = CraftManager.getInstance().getCraftByPlayer(playerSubject);
if (craft == null) {
commandSender.sendMessage("No player craft found");
return;
}
} else {
pageQuery = OptionalInt.of(1);

craftInfo(commandSender, craft, args.length == 1 ? 1 : Integer.parseInt(args[1]));
}
craftInfo(sender, craft, pageQuery.getAsInt());
return true;
}

public void craftInfo(@NotNull CommandSender commandSender, @NotNull Craft craft, int page){
public static void craftInfo(@NotNull CommandSender commandSender, @NotNull Craft craft, int page){
TopicPaginator paginator = new TopicPaginator("Craft Info");
for(var provider : providers){
for(var line : provider.apply(craft)){
Expand All @@ -106,9 +104,4 @@ public void craftInfo(@NotNull CommandSender commandSender, @NotNull Craft craft
for(String line : paginator.getPage(page))
commandSender.sendMessage(line);
}

@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.countercraft.movecraft.commands;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import net.countercraft.movecraft.craft.Craft;
import net.countercraft.movecraft.craft.CraftManager;
import net.countercraft.movecraft.craft.PilotedCraft;
Expand All @@ -11,45 +13,36 @@
import net.countercraft.movecraft.util.hitboxes.HitBox;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

public class CraftReportCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] args) {
if (commandSender.getName().equalsIgnoreCase("craftreport"))
return false;
@CommandAlias("craftreport")
@CommandPermission("movecraft.commands,movecraft.commands.craftreport")
public class CraftReportCommand extends BaseCommand {

if (!commandSender.hasPermission("movecraft.commands")
|| !commandSender.hasPermission("movecraft.commands.craftreport")) {
commandSender.sendMessage(Component.empty()
.append(ChatUtils.errorPrefix())
.append(I18nSupport.getInternationalisedComponent("Insufficient Permissions")));
return true;
}
@Default
@Syntax("<page>")
@Description("Reports on all active craft")
public static void onCommand(CommandSender commandSender, @Optional String pageString) {
int page;
try {
if (args.length == 0)
if (pageString == null)
page = 1;
else
page = Integer.parseInt(args[0]);
}
catch (NumberFormatException e) {
page = Integer.parseInt(pageString);
} catch (NumberFormatException e) {
commandSender.sendMessage(Component.empty()
.append(ChatUtils.commandPrefix())
.append(I18nSupport.getInternationalisedComponent("Paginator - Invalid Page"))
.append(Component.text("\""))
.append(Component.text(args[0]))
.append(Component.text(pageString))
.append(Component.text("\"")));
return true;
return;
}
if (CraftManager.getInstance().isEmpty()) {
commandSender.sendMessage(Component.empty()
.append(ChatUtils.commandPrefix())
.append(I18nSupport.getInternationalisedComponent("Craft Report - None Found")));
return true;
return;
}
ComponentPaginator paginator = new ComponentPaginator(
I18nSupport.getInternationalisedComponent("Craft Report"),
Expand Down Expand Up @@ -87,12 +80,11 @@ else if (craft.getDisabled())
.append(ChatUtils.commandPrefix())
.append(I18nSupport.getInternationalisedComponent("Paginator - Invalid page"))
.append(Component.text(" \""))
.append(Component.text(args[0]))
.append(Component.text(page))
.append(Component.text("\"")));
return true;
return;
}
for (Component line : paginator.getPage(page))
commandSender.sendMessage(line);
return true;
}
}
Loading