-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracted arguments into separate classes
- Loading branch information
Showing
12 changed files
with
434 additions
and
223 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
229 changes: 7 additions & 222 deletions
229
plugin/src/main/java/net/thenextlvl/commander/paper/command/CommanderCommand.java
Large diffs are not rendered by default.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
plugin/src/main/java/net/thenextlvl/commander/paper/command/HideCommand.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,44 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class HideCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("hide") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
Bukkit.getCommandMap().getKnownCommands().values().stream() | ||
.map(org.bukkit.command.Command::getLabel) | ||
.filter(s -> !plugin.commandRegistry().isHidden(s)) | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::hide)); | ||
} | ||
|
||
private int hide(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var success = plugin.commandRegistry().hide(command); | ||
var message = success ? "command.hidden" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, Placeholder.parsed("command", command)); | ||
if (success) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
plugin/src/main/java/net/thenextlvl/commander/paper/command/PermissionCommand.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,21 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class PermissionCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("permission") | ||
.then(new PermissionQueryCommand(plugin).create()) | ||
.then(new PermissionResetCommand(plugin).create()) | ||
.then(new PermissionSetCommand(plugin).create()) | ||
.then(new PermissionUnsetCommand(plugin).create()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
plugin/src/main/java/net/thenextlvl/commander/paper/command/PermissionQueryCommand.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,45 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class PermissionQueryCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("query") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
Bukkit.getCommandMap().getKnownCommands().values().stream() | ||
.map(Command::getLabel) | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::query)); | ||
} | ||
|
||
private int query(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var registered = Bukkit.getCommandMap().getKnownCommands().get(command); | ||
var permission = registered != null ? registered.getPermission() : null; | ||
var message = registered == null ? "command.unknown" : permission != null ? | ||
"permission.query.defined" : "permission.query.undefined"; | ||
plugin.bundle().sendMessage(sender, message, | ||
Placeholder.parsed("permission", String.valueOf(permission)), | ||
Placeholder.parsed("command", command)); | ||
return com.mojang.brigadier.Command.SINGLE_SUCCESS; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
plugin/src/main/java/net/thenextlvl/commander/paper/command/PermissionResetCommand.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,42 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class PermissionResetCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("reset") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
plugin.permissionOverride().originalPermissions().keySet().stream() | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::reset)); | ||
} | ||
|
||
private int reset(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var success = plugin.permissionOverride().reset(command); | ||
var message = success ? "permission.reset" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, Placeholder.parsed("command", command)); | ||
if (success) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
plugin/src/main/java/net/thenextlvl/commander/paper/command/PermissionSetCommand.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,56 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.permissions.Permission; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class PermissionSetCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("set") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
Bukkit.getCommandMap().getKnownCommands().values().stream() | ||
.map(Command::getLabel) | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.then(Commands.argument("permission", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
Bukkit.getPluginManager().getPermissions().stream() | ||
.map(Permission::getName) | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::set))); | ||
} | ||
|
||
private int set(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var permission = context.getArgument("permission", String.class); | ||
var success = plugin.permissionOverride().override(command, permission); | ||
var message = success ? "permission.set" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, | ||
Placeholder.parsed("permission", permission), | ||
Placeholder.parsed("command", command)); | ||
if (success) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
return com.mojang.brigadier.Command.SINGLE_SUCCESS; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
plugin/src/main/java/net/thenextlvl/commander/paper/command/PermissionUnsetCommand.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,45 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.entity.Player; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class PermissionUnsetCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("unset") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
Bukkit.getCommandMap().getKnownCommands().values().stream() | ||
.map(Command::getLabel) | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::unset)); | ||
} | ||
|
||
private int unset(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var success = plugin.permissionOverride().override(command, null); | ||
var message = success ? "permission.set" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, | ||
Placeholder.parsed("permission", "null"), | ||
Placeholder.parsed("command", command)); | ||
if (success) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
return com.mojang.brigadier.Command.SINGLE_SUCCESS; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
plugin/src/main/java/net/thenextlvl/commander/paper/command/RegisterCommand.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,42 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class RegisterCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("register") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
plugin.commandRegistry().unregisteredCommands().stream() | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::register)); | ||
} | ||
|
||
private int register(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var success = plugin.commandRegistry().register(command); | ||
var message = success ? "command.registered" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, Placeholder.parsed("command", command)); | ||
if (success) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
plugin/src/main/java/net/thenextlvl/commander/paper/command/ResetCommand.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,45 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class ResetCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("reset") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
plugin.commandRegistry().hiddenCommands().stream() | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
plugin.commandRegistry().unregisteredCommands().stream() | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.map(StringArgumentType::escapeIfRequired) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::reset)); | ||
} | ||
|
||
private int reset(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var s1 = plugin.permissionOverride().reset(command); | ||
var s3 = plugin.commandRegistry().register(command); | ||
var s2 = plugin.commandRegistry().reveal(command); | ||
var message = s1 || s2 || s3 ? "command.reset" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, Placeholder.parsed("command", command)); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
plugin/src/main/java/net/thenextlvl/commander/paper/command/RevealCommand.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,42 @@ | ||
package net.thenextlvl.commander.paper.command; | ||
|
||
import com.mojang.brigadier.Command; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.builder.ArgumentBuilder; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
import io.papermc.paper.command.brigadier.Commands; | ||
import lombok.RequiredArgsConstructor; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.thenextlvl.commander.paper.CommanderPlugin; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
|
||
@RequiredArgsConstructor | ||
@SuppressWarnings("UnstableApiUsage") | ||
class RevealCommand { | ||
private final CommanderPlugin plugin; | ||
|
||
public ArgumentBuilder<CommandSourceStack, ?> create() { | ||
return Commands.literal("reveal") | ||
.then(Commands.argument("command", StringArgumentType.string()) | ||
.suggests((context, suggestions) -> { | ||
plugin.commandRegistry().hiddenCommands().stream() | ||
.map(StringArgumentType::escapeIfRequired) | ||
.filter(s -> s.contains(suggestions.getRemaining())) | ||
.forEach(suggestions::suggest); | ||
return suggestions.buildFuture(); | ||
}) | ||
.executes(this::reveal)); | ||
} | ||
|
||
private int reveal(CommandContext<CommandSourceStack> context) { | ||
var sender = context.getSource().getSender(); | ||
var command = context.getArgument("command", String.class); | ||
var success = plugin.commandRegistry().reveal(command); | ||
var message = success ? "command.revealed" : "nothing.changed"; | ||
plugin.bundle().sendMessage(sender, message, Placeholder.parsed("command", command)); | ||
if (success) Bukkit.getOnlinePlayers().forEach(Player::updateCommands); | ||
return Command.SINGLE_SUCCESS; | ||
} | ||
} |
Oops, something went wrong.