Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 10 additions & 31 deletions src/main/java/com/extremelyd1/command/AllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
import com.extremelyd1.game.team.Team;
import com.extremelyd1.util.ChatUtil;
import com.extremelyd1.util.CommandUtil;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;

public class AllCommand implements TabExecutor {
@SuppressWarnings("UnstableApiUsage")
public class AllCommand implements BasicCommand {

/**
* The game instance.
Expand All @@ -29,17 +25,12 @@ public AllCommand(Game game) {
}

@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String s,
@NotNull String @NotNull [] args
) {
if (!CommandUtil.checkCommandSender(sender, false, false)) {
return true;
public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) {
if (!CommandUtil.checkCommandSender(commandSourceStack, false, false)) {
return;
}

Player player = (Player) sender;
Player player = (Player) commandSourceStack.getSender();

Team team = game.getTeamManager().getTeamByPlayer(player);
if (team == null) {
Expand All @@ -48,7 +39,7 @@ public boolean onCommand(
.color(NamedTextColor.WHITE)
));

return true;
return;
}

if (args.length == 0) {
Expand All @@ -57,7 +48,7 @@ public boolean onCommand(
.color(NamedTextColor.WHITE)
));

return true;
return;
}

String message = String.join(" ", args);
Expand All @@ -70,17 +61,5 @@ public boolean onCommand(
.color(NamedTextColor.WHITE)
)
);

return true;
}

@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String @NotNull [] args
) {
return Collections.emptyList();
}
}
30 changes: 8 additions & 22 deletions src/main/java/com/extremelyd1/command/BingoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
import com.extremelyd1.game.team.PlayerTeam;
import com.extremelyd1.util.CommandUtil;
import com.extremelyd1.util.ChatUtil;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BingoCommand implements TabExecutor {
@SuppressWarnings("UnstableApiUsage")
public class BingoCommand implements BasicCommand {

/**
* The game instance
Expand All @@ -31,17 +29,12 @@ public BingoCommand(Game game) {
}

@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String s,
String @NotNull [] strings
) {
if (CommandUtil.checkCommandSender(sender, game, false, false, true, true)) {
return true;
public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) {
if (CommandUtil.checkCommandSender(commandSourceStack, game, false, false, true, true)) {
return;
}

Player player = (Player) sender;
Player player = (Player) commandSourceStack.getSender();
PlayerTeam playerTeam = (PlayerTeam) game.getTeamManager().getTeamByPlayer(player);

List<Material> itemsCollected = new ArrayList<>();
Expand Down Expand Up @@ -86,13 +79,6 @@ public boolean onCommand(
}

player.sendMessage(message);

return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
return Collections.emptyList();
}

/**
Expand Down
45 changes: 14 additions & 31 deletions src/main/java/com/extremelyd1/command/CardCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
import com.extremelyd1.util.ChatUtil;
import com.extremelyd1.util.CommandUtil;
import com.extremelyd1.util.ItemUtil;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;

public class CardCommand implements TabExecutor {
@SuppressWarnings("UnstableApiUsage")
public class CardCommand implements BasicCommand {

/**
* The game instance
* The game instance.
*/
private final Game game;

Expand All @@ -37,17 +33,16 @@ public CardCommand(Game game, BingoCardItemFactory bingoCardItemFactory) {
}

@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String s,
String @NotNull [] strings
) {
if (CommandUtil.checkCommandSender(sender, game, false, false, true, true)) {
return true;
public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) {
if (CommandUtil.checkCommandSender(commandSourceStack, game, false, false, true, true)) {
return;
}

if (!(commandSourceStack.getExecutor() instanceof Player player)) {
commandSourceStack.getSender().sendMessage("This command can only be executed on a player");
return;
}

Player player = (Player) sender;
Team team = game.getTeamManager().getTeamByPlayer(player);

if (ItemUtil.hasBingoCard(player, bingoCardItemFactory)) {
Expand All @@ -56,7 +51,7 @@ public boolean onCommand(
.color(NamedTextColor.WHITE)
));

return true;
return;
}

player.getInventory().addItem(
Expand All @@ -67,17 +62,5 @@ public boolean onCommand(
.text("You have been given a new bingo card")
.color(NamedTextColor.WHITE)
));

return true;
}

@Override
public @Nullable List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String label,
@NotNull String @NotNull [] args
) {
return Collections.emptyList();
}
}
53 changes: 20 additions & 33 deletions src/main/java/com/extremelyd1/command/ChannelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import com.extremelyd1.game.chat.ChatChannelController;
import com.extremelyd1.util.ChatUtil;
import com.extremelyd1.util.CommandUtil;
import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Collection;

import java.util.Collections;

public class ChannelCommand implements TabExecutor {
@SuppressWarnings("UnstableApiUsage")
public class ChannelCommand implements BasicCommand {

/**
* The game instance
* The game instance.
*/
private final Game game;

Expand All @@ -29,21 +29,16 @@ public ChannelCommand(Game game) {
}

@Override
public boolean onCommand(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String s,
@NotNull String @NotNull [] args
) {
if (!CommandUtil.checkCommandSender(sender, false, false)) {
return true;
public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) {
if (!CommandUtil.checkCommandSender(commandSourceStack, false, false)) {
return;
}

Player player = (Player) sender;
Player player = (Player) commandSourceStack.getSender();

if (args.length == 0) {
sendUsage(sender, command);
return true;
sendUsage(commandSourceStack);
return;
}

try {
Expand All @@ -58,37 +53,29 @@ public boolean onCommand(
)
));
} catch (IllegalArgumentException ex) {
sendUsage(sender, command);
sendUsage(commandSourceStack);
}

return true;
}

@Override
public List<String> onTabComplete(
@NotNull CommandSender sender,
@NotNull Command command,
@NotNull String s,
@NotNull String @NotNull [] args
) {
if (!(sender instanceof Player) || args.length != 1) {
public @NotNull Collection<String> suggest(CommandSourceStack commandSourceStack, String @NotNull [] args) {
if (!(commandSourceStack.getSender() instanceof Player) || args.length != 1) {
return Collections.emptyList();
}

return Arrays.asList("team", "global");
}

/**
* Send the usage of this command to the given sender
* @param sender The sender to send the command to
* @param command The command instance
* Send the usage of this command to the given sender.
* @param commandSourceStack The command source to send the usage to.
*/
private void sendUsage(CommandSender sender, Command command) {
sender.sendMessage(Component
private void sendUsage(@NotNull CommandSourceStack commandSourceStack) {
commandSourceStack.getSender().sendMessage(Component
.text("Usage: ")
.color(NamedTextColor.DARK_RED)
.append(Component
.text("/" + command.getName() + " <team|global>")
.text("/channel <team|global>")
.color(NamedTextColor.WHITE)
)
);
Expand Down
Loading