diff --git a/src/main/java/com/extremelyd1/command/AllCommand.java b/src/main/java/com/extremelyd1/command/AllCommand.java index bd3fba9..3c492fe 100644 --- a/src/main/java/com/extremelyd1/command/AllCommand.java +++ b/src/main/java/com/extremelyd1/command/AllCommand.java @@ -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. @@ -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) { @@ -48,7 +39,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (args.length == 0) { @@ -57,7 +48,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } String message = String.join(" ", args); @@ -70,17 +61,5 @@ public boolean onCommand( .color(NamedTextColor.WHITE) ) ); - - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/BingoCommand.java b/src/main/java/com/extremelyd1/command/BingoCommand.java index 89ac99f..bd4f777 100644 --- a/src/main/java/com/extremelyd1/command/BingoCommand.java +++ b/src/main/java/com/extremelyd1/command/BingoCommand.java @@ -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 @@ -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 itemsCollected = new ArrayList<>(); @@ -86,13 +79,6 @@ public boolean onCommand( } player.sendMessage(message); - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) { - return Collections.emptyList(); } /** diff --git a/src/main/java/com/extremelyd1/command/CardCommand.java b/src/main/java/com/extremelyd1/command/CardCommand.java index 981172a..a719b5a 100644 --- a/src/main/java/com/extremelyd1/command/CardCommand.java +++ b/src/main/java/com/extremelyd1/command/CardCommand.java @@ -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; @@ -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)) { @@ -56,7 +51,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } player.getInventory().addItem( @@ -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 onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/ChannelCommand.java b/src/main/java/com/extremelyd1/command/ChannelCommand.java index b5ecb02..f3526f9 100644 --- a/src/main/java/com/extremelyd1/command/ChannelCommand.java +++ b/src/main/java/com/extremelyd1/command/ChannelCommand.java @@ -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; @@ -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 { @@ -58,20 +53,13 @@ public boolean onCommand( ) )); } catch (IllegalArgumentException ex) { - sendUsage(sender, command); + sendUsage(commandSourceStack); } - - return true; } @Override - public List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] args - ) { - if (!(sender instanceof Player) || args.length != 1) { + public @NotNull Collection suggest(CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!(commandSourceStack.getSender() instanceof Player) || args.length != 1) { return Collections.emptyList(); } @@ -79,16 +67,15 @@ public List onTabComplete( } /** - * 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() + " ") + .text("/channel ") .color(NamedTextColor.WHITE) ) ); diff --git a/src/main/java/com/extremelyd1/command/CoordinatesCommand.java b/src/main/java/com/extremelyd1/command/CoordinatesCommand.java index 806dc70..41d3d1f 100644 --- a/src/main/java/com/extremelyd1/command/CoordinatesCommand.java +++ b/src/main/java/com/extremelyd1/command/CoordinatesCommand.java @@ -4,24 +4,20 @@ 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.Location; -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 CoordinatesCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class CoordinatesCommand implements BasicCommand { /** - * The game instance + * The game instance. */ private final Game game; @@ -30,23 +26,19 @@ public CoordinatesCommand(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; } + CommandSender sender = commandSourceStack.getSender(); if (game.getState().equals(Game.State.PRE_GAME)) { sender.sendMessage(ChatUtil.errorPrefix().append(Component .text("Cannot execute this command in pre-game") .color(NamedTextColor.WHITE) )); - return true; + return; } Player player = (Player) sender; @@ -58,7 +50,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } Location location = player.getLocation(); @@ -94,16 +86,5 @@ public boolean onCommand( ) ); } - - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/DisabledCommand.java b/src/main/java/com/extremelyd1/command/DisabledCommand.java index 6c713b3..be06fef 100644 --- a/src/main/java/com/extremelyd1/command/DisabledCommand.java +++ b/src/main/java/com/extremelyd1/command/DisabledCommand.java @@ -1,41 +1,20 @@ package com.extremelyd1.command; 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.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; - -public class DisabledCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class DisabledCommand implements BasicCommand { @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - sender.sendMessage(ChatUtil.errorPrefix().append(Component + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + commandSourceStack.getSender().sendMessage(ChatUtil.errorPrefix().append(Component .text("This command is currently disabled") .color(NamedTextColor.WHITE) )); - - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/EndCommand.java b/src/main/java/com/extremelyd1/command/EndCommand.java index 2a1f792..e08e6a6 100644 --- a/src/main/java/com/extremelyd1/command/EndCommand.java +++ b/src/main/java/com/extremelyd1/command/EndCommand.java @@ -3,19 +3,15 @@ import com.extremelyd1.game.Game; import com.extremelyd1.game.winCondition.WinReason; import com.extremelyd1.util.CommandUtil; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; +import io.papermc.paper.command.brigadier.BasicCommand; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; - -public class EndCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class EndCommand implements BasicCommand { /** - * The game instance + * The game instance. */ private final Game game; @@ -24,28 +20,11 @@ public EndCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] strings - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } game.end(new WinReason()); - - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/GenerateCommand.java b/src/main/java/com/extremelyd1/command/GenerateCommand.java index f570279..5d9b82f 100644 --- a/src/main/java/com/extremelyd1/command/GenerateCommand.java +++ b/src/main/java/com/extremelyd1/command/GenerateCommand.java @@ -2,21 +2,21 @@ import com.extremelyd1.game.Game; 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.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.Collections; import java.util.List; -public class GenerateCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class GenerateCommand implements BasicCommand { /** - * The game instance + * The game instance. */ private final Game game; @@ -25,67 +25,54 @@ public GenerateCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } if (args.length < 1) { - sendUsage(sender, command); + sendUsage(commandSourceStack); - return true; + return; } if (args[0].equalsIgnoreCase("stop")) { game.getWorldManager().stopPreGeneration(); - return true; + return; } else if (args.length < 2) { - sendUsage(sender, command); + sendUsage(commandSourceStack); - return true; + return; } int start; try { start = Integer.parseInt(args[0]); } catch (NumberFormatException e) { - sendUsage(sender, command); + sendUsage(commandSourceStack); - return true; + return; } int numWorlds; try { numWorlds = Integer.parseInt(args[1]); } catch (NumberFormatException e) { - sendUsage(sender, command); + sendUsage(commandSourceStack); - return true; + return; } - sender.sendMessage( + commandSourceStack.getSender().sendMessage( "Pre-generating " + numWorlds + " worlds..." ); game.getWorldManager().createWorlds(start, numWorlds); - - return true; } @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String - @NotNull [] args - ) { + public @NotNull Collection suggest(@NotNull CommandSourceStack commandSourceStack, String[] args) { if (args.length == 1) { return List.of("stop"); } @@ -94,16 +81,15 @@ public boolean onCommand( } /** - * Send the usage of this command to the given command sender - * @param sender The command sender to send the usage to - * @param command The command instance + * Send the usage of this command to the given command 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() + " stop | ") + .text("/generate stop | ") .color(NamedTextColor.WHITE) ) ); diff --git a/src/main/java/com/extremelyd1/command/ItemDistributionCommand.java b/src/main/java/com/extremelyd1/command/ItemDistributionCommand.java index 2784916..bdc0394 100644 --- a/src/main/java/com/extremelyd1/command/ItemDistributionCommand.java +++ b/src/main/java/com/extremelyd1/command/ItemDistributionCommand.java @@ -3,19 +3,20 @@ import com.extremelyd1.game.Game; 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.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; -public class ItemDistributionCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class ItemDistributionCommand implements BasicCommand { /** * The game instance. @@ -27,19 +28,16 @@ public ItemDistributionCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] args - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } + CommandSender sender = commandSourceStack.getSender(); + if (args.length != 5) { sendItemDistributionError(sender); - return true; + return; } int numSTierItems = parseItemDistribution(args[0], sender); @@ -53,7 +51,7 @@ public boolean onCommand( || numBTierItems == -1 || numCTierItems == -1 || numDTierItems == -1) { - return true; + return; } if (numSTierItems + numATierItems + numBTierItems + numCTierItems + numDTierItems != 25) { @@ -62,7 +60,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } game.getConfig().setItemDistribution( @@ -90,8 +88,6 @@ public boolean onCommand( )); game.onPregameUpdate(); - - return true; } /** @@ -135,12 +131,7 @@ private void sendItemDistributionError(CommandSender sender) { } @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { + public @NotNull Collection suggest(@NotNull CommandSourceStack commandSourceStack, String[] args) { List list = new ArrayList<>(); // If we have more than 5 arguments, we don't suggest anymore diff --git a/src/main/java/com/extremelyd1/command/JoinCommand.java b/src/main/java/com/extremelyd1/command/JoinCommand.java index d600f16..5606f8f 100644 --- a/src/main/java/com/extremelyd1/command/JoinCommand.java +++ b/src/main/java/com/extremelyd1/command/JoinCommand.java @@ -4,18 +4,20 @@ import com.extremelyd1.game.team.PlayerTeam; 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.ArrayList; +import java.util.Collection; import java.util.List; -public class JoinCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class JoinCommand implements BasicCommand { /** * The game instance. @@ -27,16 +29,13 @@ public JoinCommand(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; } + CommandSender sender = commandSourceStack.getSender(); + // Prevent the command from being used anything apart from pre-game if (!game.getState().equals(Game.State.PRE_GAME)) { sender.sendMessage(ChatUtil.errorPrefix().append(Component @@ -44,14 +43,20 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } - Player player = (Player) sender; - if (args.length == 0) { - sendUsage(sender, command); - return true; + sendUsage(sender); + return; + } + + if (!(commandSourceStack.getExecutor() instanceof Player player)) { + sender.sendMessage(ChatUtil.errorPrefix().append(Component + .text("Cannot execute this command for a non-player entity") + .color(NamedTextColor.WHITE) + )); + return; } PlayerTeam checkTeam = game.getTeamManager().getTeamByName(args[0]); @@ -64,36 +69,28 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); } - - return true; } /** * Send the usage of this command to the given sender. * @param sender The sender to send the command to. - * @param command The command instance. */ - private void sendUsage(CommandSender sender, Command command) { + private void sendUsage(CommandSender sender) { sender.sendMessage(Component .text("Usage: ") .color(NamedTextColor.DARK_RED) .append(Component - .text("/" + command.getName() + " ") + .text("/join ") .color(NamedTextColor.WHITE) ) ); } @Override - public List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] args - ) { + public @NotNull Collection suggest(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { List teams = new ArrayList<>(); - if (!(sender instanceof Player) || args.length != 1) { + if (!(commandSourceStack.getSender() instanceof Player) || args.length != 1) { return teams; } diff --git a/src/main/java/com/extremelyd1/command/MaintenanceCommand.java b/src/main/java/com/extremelyd1/command/MaintenanceCommand.java index c12ac9b..eea9b9f 100644 --- a/src/main/java/com/extremelyd1/command/MaintenanceCommand.java +++ b/src/main/java/com/extremelyd1/command/MaintenanceCommand.java @@ -2,19 +2,15 @@ import com.extremelyd1.game.Game; 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.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; - -public class MaintenanceCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class MaintenanceCommand implements BasicCommand { /** * The game instance @@ -26,14 +22,9 @@ public MaintenanceCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - String @NotNull [] strings - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } game.toggleMaintenance(); @@ -52,16 +43,5 @@ public boolean onCommand( } Bukkit.broadcast(message); - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/PvpCommand.java b/src/main/java/com/extremelyd1/command/PvpCommand.java index 2ac7420..7175601 100644 --- a/src/main/java/com/extremelyd1/command/PvpCommand.java +++ b/src/main/java/com/extremelyd1/command/PvpCommand.java @@ -2,19 +2,15 @@ import com.extremelyd1.game.Game; 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.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; - -public class PvpCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class PvpCommand implements BasicCommand { /** * The game instance @@ -26,14 +22,9 @@ public PvpCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, String - @NotNull [] strings - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } game.togglePvp(); @@ -52,16 +43,5 @@ public boolean onCommand( } Bukkit.broadcast(message); - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/RerollCommand.java b/src/main/java/com/extremelyd1/command/RerollCommand.java index 86e2652..8b21ea4 100644 --- a/src/main/java/com/extremelyd1/command/RerollCommand.java +++ b/src/main/java/com/extremelyd1/command/RerollCommand.java @@ -3,18 +3,15 @@ import com.extremelyd1.game.Game; 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.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; - -public class RerollCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class RerollCommand implements BasicCommand { /** * The game instance @@ -26,18 +23,20 @@ public RerollCommand(Game game) { } @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, String @NotNull [] strings) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } + CommandSender sender = commandSourceStack.getSender(); + if (!game.getState().equals(Game.State.IN_GAME)) { sender.sendMessage(ChatUtil.errorPrefix().append(Component .text("Can only use this command in-game") .color(NamedTextColor.WHITE) )); - return true; + return; } game.rerollCard(); @@ -46,12 +45,5 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command .text("Rerolled bingo card") .color(NamedTextColor.WHITE) )); - - return true; - } - - @Override - public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/StartCommand.java b/src/main/java/com/extremelyd1/command/StartCommand.java index aa7e607..ea36f58 100644 --- a/src/main/java/com/extremelyd1/command/StartCommand.java +++ b/src/main/java/com/extremelyd1/command/StartCommand.java @@ -3,19 +3,16 @@ import com.extremelyd1.game.Game; 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 org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; - -public class StartCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class StartCommand implements BasicCommand { /** * The game instance. @@ -27,23 +24,20 @@ public StartCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] strings - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } + CommandSender sender = commandSourceStack.getSender(); + if (game.getState().equals(Game.State.IN_GAME)) { sender.sendMessage(ChatUtil.errorPrefix().append(Component .text("Cannot start game, it has already been started") .color(NamedTextColor.WHITE) )); - return true; + return; } if (sender instanceof Player) { @@ -51,17 +45,5 @@ public boolean onCommand( } else { game.start(); } - - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/TeamChatCommand.java b/src/main/java/com/extremelyd1/command/TeamChatCommand.java index 9f2601e..551cad1 100644 --- a/src/main/java/com/extremelyd1/command/TeamChatCommand.java +++ b/src/main/java/com/extremelyd1/command/TeamChatCommand.java @@ -4,19 +4,15 @@ 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.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 TeamChatCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class TeamChatCommand implements BasicCommand { /** * The game instance @@ -28,21 +24,16 @@ public TeamChatCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] strings - ) { - 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); - String message = String.join(" ", strings); + String message = String.join(" ", args); if (team == null) { player.sendMessage(ChatUtil.errorPrefix().append(Component @@ -61,17 +52,5 @@ public boolean onCommand( ); } } - - return true; - } - - @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - return Collections.emptyList(); } } diff --git a/src/main/java/com/extremelyd1/command/TeamCommand.java b/src/main/java/com/extremelyd1/command/TeamCommand.java index 34acf26..36ae63d 100644 --- a/src/main/java/com/extremelyd1/command/TeamCommand.java +++ b/src/main/java/com/extremelyd1/command/TeamCommand.java @@ -6,23 +6,23 @@ import com.extremelyd1.game.team.TeamManager; 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.*; import java.util.stream.Collectors; -public class TeamCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class TeamCommand implements BasicCommand { /** - * The game instance + * The game instance. */ private final Game game; @@ -31,20 +31,17 @@ public TeamCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } + CommandSender sender = commandSourceStack.getSender(); + if (args.length == 0) { - sendUsage(sender, command); + sendUsage(sender); - return true; + return; } if (!game.getState().equals(Game.State.PRE_GAME)) { @@ -53,14 +50,14 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (args[0].equalsIgnoreCase("random")) { if (args.length < 2) { - sendUsageRandom(sender, command); + sendUsageRandom(sender); - return true; + return; } int numTeams; @@ -72,7 +69,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (numTeams <= 0) { @@ -81,7 +78,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (numTeams >= TeamManager.MAX_TEAMS) { @@ -90,7 +87,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } Collection players = Bukkit.getOnlinePlayers(); @@ -98,8 +95,8 @@ public boolean onCommand( if (args.length > 2) { if (args[2].equalsIgnoreCase("-e")) { if (args.length < 4) { - sendUsageRandom(sender, command); - return true; + sendUsageRandom(sender); + return; } Collection excludedPlayers = parsePlayerArguments(args, 3); @@ -109,7 +106,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } // Filter the online players to exclude the players given in the command @@ -127,7 +124,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } game.getTeamManager().createRandomizedTeams( @@ -146,12 +143,12 @@ public boolean onCommand( .text("Usage: ") .color(NamedTextColor.DARK_RED) .append(Component - .text("/" + command.getName() + " add ") + .text("/team add ") .color(NamedTextColor.WHITE) ) ); - return true; + return; } Player argumentPlayer = getPlayerByName(args[1]); @@ -161,7 +158,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } TeamManager teamManager = game.getTeamManager(); @@ -173,7 +170,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } teamManager.addPlayerToTeam(argumentPlayer, argumentTeam, true); @@ -183,12 +180,12 @@ public boolean onCommand( .text("Usage: ") .color(NamedTextColor.DARK_RED) .append(Component - .text("/" + command.getName() + " remove ") + .text("/team remove ") .color(NamedTextColor.WHITE) ) ); - return true; + return; } Player argumentPlayer = getPlayerByName(args[1]); @@ -198,7 +195,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } TeamManager teamManager = game.getTeamManager(); @@ -210,32 +207,29 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } // Add player to spectators teamManager.addPlayerToTeam(argumentPlayer, teamManager.getSpectatorTeam()); } else { - sendUsage(sender, command); - return true; + sendUsage(sender); + return; } game.onPregameUpdate(); - - return true; } /** * Send the usage of this command to the given sender. * @param sender The sender to send the command to. - * @param command The command instance. */ - private void sendUsage(CommandSender sender, Command command) { + private void sendUsage(CommandSender sender) { sender.sendMessage(Component .text("Usage: ") .color(NamedTextColor.DARK_RED) .append(Component - .text("/" + command.getName() + " ") + .text("/team ") .color(NamedTextColor.WHITE) ) ); @@ -243,14 +237,13 @@ private void sendUsage(CommandSender sender, Command command) { /** * Send the usage of the random sub command. - * @param sender The sender to send the usage to. */ - private void sendUsageRandom(CommandSender sender, Command command) { + private void sendUsageRandom(CommandSender sender) { sender.sendMessage(Component .text("Usage: ") .color(NamedTextColor.DARK_RED) .append(Component - .text("/" + command.getName() + " random [-e] [players...]") + .text("/team random [-e] [players...]") .color(NamedTextColor.WHITE) ) ); @@ -294,12 +287,7 @@ private Collection parsePlayerArguments(String[] args, int index) { } @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { + public @NotNull Collection suggest(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { if (!game.getState().equals(Game.State.PRE_GAME)) { return Collections.emptyList(); } diff --git a/src/main/java/com/extremelyd1/command/TimerCommand.java b/src/main/java/com/extremelyd1/command/TimerCommand.java index 0d4292c..162a32d 100644 --- a/src/main/java/com/extremelyd1/command/TimerCommand.java +++ b/src/main/java/com/extremelyd1/command/TimerCommand.java @@ -4,21 +4,21 @@ import com.extremelyd1.util.ChatUtil; import com.extremelyd1.util.CommandUtil; import com.extremelyd1.util.TimeUtil; +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 net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Bukkit; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.List; -public class TimerCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class TimerCommand implements BasicCommand { /** * The game instance @@ -30,23 +30,20 @@ public TimerCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] args - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } + CommandSender sender = commandSourceStack.getSender(); + if (args.length == 0) { sender.sendMessage(ChatUtil.errorPrefix().append(Component .text("Please provide either 'enable/disable' or a time limit") .color(NamedTextColor.WHITE) )); - return true; + return; } if (!game.getState().equals(Game.State.PRE_GAME)) { @@ -55,7 +52,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (args[0].equalsIgnoreCase("enable")) { @@ -71,7 +68,7 @@ public boolean onCommand( game.onPregameUpdate(); - return true; + return; } else if (args[0].equalsIgnoreCase("disable")) { game.getConfig().setTimerEnabled(false); @@ -85,7 +82,7 @@ public boolean onCommand( game.onPregameUpdate(); - return true; + return; } int timerLength; @@ -95,7 +92,7 @@ public boolean onCommand( game.onPregameUpdate(); - return true; + return; } catch (NumberFormatException ignored) { // Timer is not specified in a single integer } @@ -115,14 +112,12 @@ public boolean onCommand( ) )); - return true; + return; } trySetTimer(sender, parsedTime); game.onPregameUpdate(); - - return true; } private void trySetTimer(CommandSender sender, int seconds) { @@ -151,12 +146,7 @@ private void trySetTimer(CommandSender sender, int seconds) { } @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { + public @NotNull Collection suggest(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { if (!game.getState().equals(Game.State.PRE_GAME)) { return Collections.emptyList(); } diff --git a/src/main/java/com/extremelyd1/command/WinConditionCommand.java b/src/main/java/com/extremelyd1/command/WinConditionCommand.java index 97921a3..4bd23e0 100644 --- a/src/main/java/com/extremelyd1/command/WinConditionCommand.java +++ b/src/main/java/com/extremelyd1/command/WinConditionCommand.java @@ -4,22 +4,19 @@ import com.extremelyd1.game.team.TeamManager; 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 net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Bukkit; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.command.TabExecutor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; -public class WinConditionCommand implements TabExecutor { +@SuppressWarnings("UnstableApiUsage") +public class WinConditionCommand implements BasicCommand { /** * The game instance @@ -31,23 +28,20 @@ public WinConditionCommand(Game game) { } @Override - public boolean onCommand( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String s, - @NotNull String @NotNull [] args - ) { - if (!CommandUtil.checkCommandSender(sender, true, true)) { - return true; + public void execute(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { + if (!CommandUtil.checkCommandSender(commandSourceStack, true, true)) { + return; } + CommandSender sender = commandSourceStack.getSender(); + if (!game.getState().equals(Game.State.PRE_GAME)) { sender.sendMessage(ChatUtil.errorPrefix().append(Component .text("Can only execute this command in pre-game") .color(NamedTextColor.WHITE) )); - return true; + return; } if (args.length == 0) { @@ -56,7 +50,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (args[0].equalsIgnoreCase("full")) { @@ -73,7 +67,7 @@ public boolean onCommand( game.onPregameUpdate(); - return true; + return; } else if (args[0].equalsIgnoreCase("lines")) { if (args.length < 2) { sender.sendMessage(ChatUtil.errorPrefix().append(Component @@ -81,7 +75,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } int numLines; @@ -93,7 +87,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } if (numLines < 1 || numLines > 10) { @@ -115,7 +109,7 @@ public boolean onCommand( ) )); - return true; + return; } game.getWinConditionChecker().setNumLinesToComplete(numLines); @@ -131,7 +125,7 @@ public boolean onCommand( game.onPregameUpdate(); - return true; + return; } else if (args[0].equalsIgnoreCase("lockout")) { int completionsToLock = 1; if (args.length > 1) { @@ -143,7 +137,7 @@ public boolean onCommand( .color(NamedTextColor.WHITE) )); - return true; + return; } } @@ -167,7 +161,7 @@ public boolean onCommand( ) )); - return true; + return; } game.getWinConditionChecker().setCompletionsToLock(completionsToLock); @@ -200,24 +194,17 @@ public boolean onCommand( game.onPregameUpdate(); - return true; + return; } sender.sendMessage(ChatUtil.errorPrefix().append(Component .text("Please provide a valid win condition type: 'full', 'lines' or 'lockout'") .color(NamedTextColor.WHITE) )); - - return true; } @Override - public @Nullable List onTabComplete( - @NotNull CommandSender sender, - @NotNull Command command, - @NotNull String label, - @NotNull String @NotNull [] args - ) { + public @NotNull Collection suggest(@NotNull CommandSourceStack commandSourceStack, String @NotNull [] args) { if (!game.getState().equals(Game.State.PRE_GAME)) { return Collections.emptyList(); } diff --git a/src/main/java/com/extremelyd1/config/Config.java b/src/main/java/com/extremelyd1/config/Config.java index 667545e..6320b58 100644 --- a/src/main/java/com/extremelyd1/config/Config.java +++ b/src/main/java/com/extremelyd1/config/Config.java @@ -60,10 +60,10 @@ public class Config { */ private final int netherBorderSize; /** - * Whether to override world generation when using pre-generated maps to prevent lag from chunks outside the - * world border. + * Whether to override world generation when using pre-generated maps to prevent lag from generating chunks + * outside the world border. */ - private final boolean overrideWorldGeneration; + private final boolean generateEmptyChunks; /** * Whether to prevent teams from spawning in water @@ -152,7 +152,7 @@ public Config(JavaPlugin plugin) throws IllegalArgumentException { borderEnabled = config.getBoolean("border.enable"); overworldBorderSize = config.getInt("border.overworld-size"); netherBorderSize = config.getInt("border.nether-size"); - overrideWorldGeneration = config.getBoolean("border.override-world-generation"); + generateEmptyChunks = config.getBoolean("border.generation.empty-chunks-outside-border"); if (overworldBorderSize < netherBorderSize) { throw new IllegalArgumentException("Nether border should be at most as large as the overworld border size"); @@ -262,8 +262,8 @@ public int getNetherBorderSize() { return netherBorderSize; } - public boolean isOverrideWorldGeneration() { - return overrideWorldGeneration; + public boolean shouldGenerateEmptyChunks() { + return generateEmptyChunks; } public boolean isTimerEnabled() { diff --git a/src/main/java/com/extremelyd1/game/Game.java b/src/main/java/com/extremelyd1/game/Game.java index b77ff2b..51049e0 100644 --- a/src/main/java/com/extremelyd1/game/Game.java +++ b/src/main/java/com/extremelyd1/game/Game.java @@ -21,11 +21,11 @@ import com.extremelyd1.util.*; import com.extremelyd1.world.WorldManager; import com.extremelyd1.world.spawn.SpawnLoader; +import io.papermc.paper.command.brigadier.BasicCommand; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.*; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -175,44 +175,44 @@ private void registerListeners(JavaPlugin plugin) { } /** - * Register all commands - * @param plugin The plugin instance to register the commands to + * Register all commands. + * @param plugin The plugin instance to register the commands to. */ + @SuppressWarnings("UnstableApiUsage") private void registerCommands(JavaPlugin plugin) { - final Game game = this; - final Map executors = new HashMap<>() {{ - put("team", new TeamCommand(game)); - put("start", new StartCommand(game)); - put("end", new EndCommand(game)); - put("bingo", new BingoCommand(game)); - put("card", new CardCommand(game, bingoCardItemFactory)); - put("pvp", new PvpCommand(game)); - put("maintenance", new MaintenanceCommand(game)); - put("wincondition", new WinConditionCommand(game)); - put("reroll", new RerollCommand(game)); - put("itemdistribution", new ItemDistributionCommand(game)); - put("timer", new TimerCommand(game)); - put("coordinates", new CoordinatesCommand(game)); - put("all", new AllCommand(game)); - put("channel", new ChannelCommand(game)); - put("teamchat", new TeamChatCommand(game)); - put("join", new JoinCommand(game)); - - if (config.isPreGenerateWorlds()) { - put("generate", new GenerateCommand(game)); - } else { - put("generate", new DisabledCommand()); - } - }}; + plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> { + final Game game = this; + final Map commands = new HashMap<>() {{ + put(new String[] {"team"}, new TeamCommand(game)); + put(new String[] {"start"}, new StartCommand(game)); + put(new String[] {"end"}, new EndCommand(game)); + put(new String[] {"bingo"}, new BingoCommand(game)); + put(new String[] {"card"}, new CardCommand(game, bingoCardItemFactory)); + put(new String[] {"pvp"}, new PvpCommand(game)); + put(new String[] {"maintenance"}, new MaintenanceCommand(game)); + put(new String[] {"wincondition", "wincon"}, new WinConditionCommand(game)); + put(new String[] {"reroll"}, new RerollCommand(game)); + put(new String[] {"itemdistribution", "itemdist", "distribution", "dist"}, new ItemDistributionCommand(game)); + put(new String[] {"timer"}, new TimerCommand(game)); + put(new String[] {"coordinates", "coord", "coords"}, new CoordinatesCommand(game)); + put(new String[] {"all", "a", "g", "global"}, new AllCommand(game)); + put(new String[] {"channel", "c"}, new ChannelCommand(game)); + put(new String[] {"teamchat", "tc"}, new TeamChatCommand(game)); + put(new String[] {"join"}, new JoinCommand(game)); + + if (config.isPreGenerateWorlds()) { + put(new String[] {"generate", "gen"}, new GenerateCommand(game)); + } else { + put(new String[] {"generate", "gen"}, new DisabledCommand()); + } + }}; - for (String cmdName : executors.keySet()) { - PluginCommand command = plugin.getCommand(cmdName); - if (command != null) { - command.setExecutor(executors.get(cmdName)); - } else { - throw new IllegalStateException("Command " + cmdName + " could not be registered"); + for (Map.Entry entry : commands.entrySet()) { + for (String commandName : entry.getKey()) { + event.registrar().register(commandName, entry.getValue()); + } } - } + }); } /** diff --git a/src/main/java/com/extremelyd1/main/Bingo.java b/src/main/java/com/extremelyd1/main/Bingo.java index 960ad7e..9f743a3 100644 --- a/src/main/java/com/extremelyd1/main/Bingo.java +++ b/src/main/java/com/extremelyd1/main/Bingo.java @@ -9,11 +9,17 @@ import org.jetbrains.annotations.Nullable; public class Bingo extends JavaPlugin { + /** + * The game instance, used to pass to the chunk generator when it is requested. + */ + private Game game; + @Override public void onEnable() { getLogger().info("Creating Game instance"); try { - new Game(this); + this.game = new Game(this); + getLogger().info("Game instance created"); } catch (IllegalArgumentException e) { getLogger().severe(String.format("Could not start plugin: %s", e.getMessage())); Bukkit.getPluginManager().disablePlugin(this); @@ -22,6 +28,6 @@ public void onEnable() { @Override public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) { - return new BingoChunkGenerator(); + return new BingoChunkGenerator(game); } } diff --git a/src/main/java/com/extremelyd1/main/BingoBootstrap.java b/src/main/java/com/extremelyd1/main/BingoBootstrap.java new file mode 100644 index 0000000..c2f6976 --- /dev/null +++ b/src/main/java/com/extremelyd1/main/BingoBootstrap.java @@ -0,0 +1,92 @@ +package com.extremelyd1.main; + +import com.extremelyd1.util.FileUtil; +import io.papermc.paper.datapack.DatapackRegistrar; +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; + +@SuppressWarnings({"unused", "UnstableApiUsage"}) +public class BingoBootstrap implements PluginBootstrap { + /** + * The name of the directory that stores datapacks either on disk or in our embedded resources. + */ + private static final String DATAPACK_DIR_NAME = "datapacks"; + /** + * The name of the directory for the biome size datapack. + */ + private static final String BIOME_SIZE_DIR_NAME = "biome-size"; + + @Override + public void bootstrap(BootstrapContext context) { + // First check for the existence of the plugin's configuration file + File configFile = new File(context.getDataDirectory().toFile(), "config.yml"); + if (!configFile.exists()) { + // If it doesn't exist yet, it will be unpacked from the jar with default values, meaning that loading + // the datapack is unnecessary, because the default value for the biome-size config key will be normal + context.getLogger().info("Config file does not exist yet, not copying resource datapack"); + return; + } + + // Manually load the configuration file, given that we do not have access to it by other means + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + + // Check whether the border is enabled in our config. If not, we do not make use of the datapack + boolean worldBorderEnabled = config.getBoolean("border.enable"); + if (!worldBorderEnabled) { + context.getLogger().info("World border is not enabled, not copying resource datapack"); + return; + } + + // Get the config value for biome size + String biomeSize = config.getString("border.generation.biome-size"); + + // Either the biome-size key is not defined, or it is not set to 'small', so we do not provide a datapack + if (biomeSize == null || !biomeSize.equals("small")) { + context.getLogger().info("Biome size config key does not exist or is not set to 'small', not copying resource datapack"); + return; + } + + // Get the data directory of our plugin (this is more of a sanity check, because we already check for the + // existence of the config file, which should also be in there) + File dataDir = context.getDataDirectory().toFile(); + if (!dataDir.exists()) { + context.getLogger().error("Could not unpack datapack, because data directory does not exist"); + return; + } + + // Get the directory that stores the datapack + File datapackDir = new File(dataDir, DATAPACK_DIR_NAME); + if (!datapackDir.exists()) { + // If it doesn't exist yet, we try to copy the datapack directory from our embedded resources + try { + FileUtil.copyResourceDirectory(DATAPACK_DIR_NAME, datapackDir.toPath()); + } catch (URISyntaxException | IOException e) { + context.getLogger().error("Could not copy resource datapack to the data directory:\n{}", e.toString()); + return; + } + + context.getLogger().info("Successfully unpacked biome size resource datapack"); + } else { + context.getLogger().info("Biome size resource datapack already exists"); + } + + // Finally use the lifecycle event manager to discover our datapack on disk at the specified directory + final LifecycleEventManager<@NotNull BootstrapContext> manager = context.getLifecycleManager(); + manager.registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, event -> { + DatapackRegistrar registrar = event.registrar(); + try { + registrar.discoverPack(new File(datapackDir, BIOME_SIZE_DIR_NAME).toPath(), "world-gen"); + } catch (IOException e) { + context.getLogger().error("Could not discover biome size resource datapack:\n{}", e.toString()); + } + }); + } +} diff --git a/src/main/java/com/extremelyd1/util/CommandUtil.java b/src/main/java/com/extremelyd1/util/CommandUtil.java index f0e0e58..c9746cc 100644 --- a/src/main/java/com/extremelyd1/util/CommandUtil.java +++ b/src/main/java/com/extremelyd1/util/CommandUtil.java @@ -3,35 +3,37 @@ import com.extremelyd1.game.Game; import com.extremelyd1.game.team.Team; import com.extremelyd1.game.team.TeamManager; +import io.papermc.paper.command.brigadier.CommandSourceStack; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +@SuppressWarnings("UnstableApiUsage") public class CommandUtil { /** - * Checks whether the command sender has permission to execute a command. - * @param sender The sender to check. + * Checks whether the given command source has permission to execute a command. + * @param commandSourceStack The source of the command execution. * @return True if the sender is a player and has OP rights; False otherwise. */ - public static boolean checkCommandSender(CommandSender sender) { - return checkCommandSender(sender, false, true); + public static boolean checkCommandSender(@NotNull CommandSourceStack commandSourceStack) { + return checkCommandSender(commandSourceStack, false, true); } /** - * Checks whether the command sender has permission to execute a command. - * @param sender The sender to check. + * Checks whether the given command source has permission to execute a command. + * @param commandSourceStack The source of the command execution. * @param allowConsole Whether to allow console to execute. * @param needsOp Whether the player needs to be OP to execute. * @return True if the sender is allowed to execute the given command. */ - public static boolean checkCommandSender(CommandSender sender, boolean allowConsole, boolean needsOp) { - if (!(sender instanceof Player player)) { + public static boolean checkCommandSender(@NotNull CommandSourceStack commandSourceStack, boolean allowConsole, boolean needsOp) { + if (!(commandSourceStack.getSender() instanceof Player player)) { if (!allowConsole) { - sender.sendMessage("This command can only be executed as a player"); + commandSourceStack.getSender().sendMessage("This command can only be executed as a player"); return false; } else { @@ -57,8 +59,8 @@ public static boolean checkCommandSender(CommandSender sender, boolean allowCons } /** - * Checks whether the command sender has permission to execute a command. - * @param sender The sender to check. + * Checks whether the given command source has permission to execute a command. + * @param commandSourceStack The source of the command execution. * @param allowConsole Whether to allow console to execute. * @param needsOp Whether the player needs to be OP to execute. * @param requiresInGame Whether the game state needs to be in-game. @@ -66,18 +68,18 @@ public static boolean checkCommandSender(CommandSender sender, boolean allowCons * @return True if the sender is allowed to execute the given command. */ public static boolean checkCommandSender( - CommandSender sender, + @NotNull CommandSourceStack commandSourceStack, Game game, boolean allowConsole, boolean needsOp, boolean requiresInGame, boolean disallowSpectator ) { - if (!checkCommandSender(sender, allowConsole, needsOp)) { + if (!checkCommandSender(commandSourceStack, allowConsole, needsOp)) { return true; } - Player player = (Player) sender; + Player player = (Player) commandSourceStack.getSender(); if (requiresInGame && !game.getState().equals(Game.State.IN_GAME)) { player.sendMessage(ChatUtil.errorPrefix().append(Component diff --git a/src/main/java/com/extremelyd1/util/FileUtil.java b/src/main/java/com/extremelyd1/util/FileUtil.java index ed84a32..e4e9048 100644 --- a/src/main/java/com/extremelyd1/util/FileUtil.java +++ b/src/main/java/com/extremelyd1/util/FileUtil.java @@ -2,12 +2,17 @@ import com.extremelyd1.game.Game; import org.bukkit.Material; +import org.jetbrains.annotations.NotNull; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.*; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Collections; +import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.Deflater; @@ -250,4 +255,51 @@ private static String buildPath(String path, String file) { } } + /** + * Copy a given directory resource to the given target path. + * @param sourceResource The embedded source. + * @param target The target path of the directory. + * @throws URISyntaxException Thrown if the given resource cannot be found. + * @throws IOException Thrown if the directory can not be successfully copied. + */ + public static void copyResourceDirectory(String sourceResource, Path target) throws URISyntaxException, IOException { + URI resource = Objects.requireNonNull(FileUtil.class.getResource("")).toURI(); + try (FileSystem fileSystem = FileSystems.newFileSystem( + resource, + Collections.emptyMap() + )) { + final Path jarPath = fileSystem.getPath(sourceResource); + + copyDirectory(jarPath, target); + } + } + + /** + * Copy the directory at the given source path to the given target path. + * @param source The source path of the directory. + * @param target The target path of the directory. + * @param options Copy options to be used for copying. + * @throws IOException Thrown when the copy could be successfully performed. + */ + public static void copyDirectory(Path source, Path target, CopyOption... options) throws IOException { + Files.walkFileTree(source, new SimpleFileVisitor<>() { + @Override + public @NotNull FileVisitResult preVisitDirectory( + Path dir, + @NotNull BasicFileAttributes attrs + ) throws IOException { + Files.createDirectories(target.resolve(source.relativize(dir).toString())); + return FileVisitResult.CONTINUE; + } + + @Override + public @NotNull FileVisitResult visitFile( + Path file, + @NotNull BasicFileAttributes attrs + ) throws IOException { + Files.copy(file, target.resolve(source.relativize(file).toString()), options); + return FileVisitResult.CONTINUE; + } + }); + } } diff --git a/src/main/java/com/extremelyd1/world/WorldManager.java b/src/main/java/com/extremelyd1/world/WorldManager.java index e1dd509..86bc5e5 100644 --- a/src/main/java/com/extremelyd1/world/WorldManager.java +++ b/src/main/java/com/extremelyd1/world/WorldManager.java @@ -52,7 +52,7 @@ public class WorldManager implements Listener { public WorldManager(Game game) throws IllegalArgumentException { this.game = game; - if (game.getConfig().isBorderEnabled() && game.getConfig().isOverrideWorldGeneration()) { + if (game.getConfig().isBorderEnabled() && game.getConfig().shouldGenerateEmptyChunks()) { Server server = Bukkit.getServer(); CraftServer craftServer = (CraftServer) server; @@ -174,7 +174,7 @@ private void setWorldBorder( ); if (structureSearchResult == null) { - Game.getLogger().warning("Could not find structure " + bukkitStructureType + Game.getLogger().warning("Could not find structure " + bukkitStructureType.getKey() + " within " + StructureSearchRadius + " blocks in world type " + world.getEnvironment() ); @@ -244,6 +244,12 @@ private void setWorldBorder( int centerX = random.nextInt(centerMaxX - centerMinX + 1) + centerMinX; int centerZ = random.nextInt(centerMaxZ - centerMinZ + 1) + centerMinZ; + Game.getLogger().info("Setting world border at x: %s, z: %s, with size: %s".formatted( + centerX, + centerZ, + size + )); + WorldBorder border = world.getWorldBorder(); border.setCenter(centerX, centerZ); border.setSize(size); diff --git a/src/main/java/com/extremelyd1/world/generation/BingoChunkGenerator.java b/src/main/java/com/extremelyd1/world/generation/BingoChunkGenerator.java index 0e118de..9d8428c 100644 --- a/src/main/java/com/extremelyd1/world/generation/BingoChunkGenerator.java +++ b/src/main/java/com/extremelyd1/world/generation/BingoChunkGenerator.java @@ -1,6 +1,7 @@ package com.extremelyd1.world.generation; -import org.bukkit.Material; +import com.extremelyd1.game.Game; +import org.bukkit.*; import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.WorldInfo; import org.jetbrains.annotations.NotNull; @@ -11,9 +12,75 @@ * Chunk generator that generates only barrier blocks in all chunks. */ public class BingoChunkGenerator extends ChunkGenerator { + /** + * The game instance to get access to the worlds. + */ + private final Game game; + + public BingoChunkGenerator(Game game) { + this.game = game; + } @Override public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ, @NotNull ChunkData chunkData) { - chunkData.setRegion(0, chunkData.getMinHeight(), 0, 16, chunkData.getMaxHeight(), 16, Material.BARRIER); + // If we don't use vanilla generation, we fill the chunk with barrier blocks instead for fast generation + if (!shouldGenerate(worldInfo, chunkX, chunkZ)) { + chunkData.setRegion(0, chunkData.getMinHeight(), 0, 16, chunkData.getMaxHeight(), 16, Material.BARRIER); + } + } + + /** + * Whether to use vanilla generation for the given chunk in the world with the given world info. + * @param worldInfo The world info for the generation. + * @param chunkX The X coordinate of the chunk. + * @param chunkZ The Z coordinate of the chunk. + * @return True if vanilla generation should be used, false otherwise. + */ + private boolean shouldGenerate(@NotNull WorldInfo worldInfo, int chunkX, int chunkZ) { + if (game.getWorldManager() == null) { + return true; + } + + World world = Bukkit.getWorld(worldInfo.getName()); + if (world == null) { + return true; + } + + WorldBorder border = world.getWorldBorder(); + + return border.isInside(new Location(world, chunkX * 16, 0, chunkZ * 16)) || + border.isInside(new Location(world, (chunkX + 1) * 16, 0, chunkZ * 16)) || + border.isInside(new Location(world, (chunkX + 1) * 16, 0, (chunkZ + 1) * 16)) || + border.isInside(new Location(world, chunkX * 16, 0, (chunkZ + 1) * 16)); + } + + @Override + public boolean shouldGenerateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ) { + return shouldGenerate(worldInfo, chunkX, chunkZ); + } + + @Override + public boolean shouldGenerateSurface(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ) { + return shouldGenerate(worldInfo, chunkX, chunkZ); + } + + @Override + public boolean shouldGenerateCaves(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ) { + return shouldGenerate(worldInfo, chunkX, chunkZ); + } + + @Override + public boolean shouldGenerateDecorations(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ) { + return shouldGenerate(worldInfo, chunkX, chunkZ); + } + + @Override + public boolean shouldGenerateMobs(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ) { + return shouldGenerate(worldInfo, chunkX, chunkZ); + } + + @Override + public boolean shouldGenerateStructures(@NotNull WorldInfo worldInfo, @NotNull Random random, int chunkX, int chunkZ) { + return shouldGenerate(worldInfo, chunkX, chunkZ); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7a57cbb..1757edd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -21,7 +21,9 @@ border: enable: True overworld-size: 3000 nether-size: 1000 - override-world-generation: False + generation: + empty-chunks-outside-border: True + biome-size: normal timer: enable: True length: 1800 diff --git a/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/continentalness.json b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/continentalness.json new file mode 100644 index 0000000..b8de57f --- /dev/null +++ b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/continentalness.json @@ -0,0 +1,14 @@ +{ + "amplitudes": [ + 1, + 1, + 2, + 2, + 2, + 1, + 1, + 1, + 1 + ], + "firstOctave": -8 +} \ No newline at end of file diff --git a/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/erosion.json b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/erosion.json new file mode 100644 index 0000000..167e626 --- /dev/null +++ b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/erosion.json @@ -0,0 +1,10 @@ +{ + "amplitudes": [ + 1.2, + 1.4, + 0, + 1, + 1 + ], + "firstOctave": -9 +} \ No newline at end of file diff --git a/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/temperature.json b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/temperature.json new file mode 100644 index 0000000..0252bfe --- /dev/null +++ b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/temperature.json @@ -0,0 +1,11 @@ +{ + "amplitudes": [ + 1.5, + 0, + 1, + 0, + 0, + 0 + ], + "firstOctave": -9 +} diff --git a/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/vegetation.json b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/vegetation.json new file mode 100644 index 0000000..f522ded --- /dev/null +++ b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise/vegetation.json @@ -0,0 +1,11 @@ +{ + "amplitudes": [ + 1, + 1, + 0, + 0, + 0, + 0 + ], + "firstOctave": -7 +} \ No newline at end of file diff --git a/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise_settings/nether.json b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise_settings/nether.json new file mode 100644 index 0000000..fd1ed4c --- /dev/null +++ b/src/main/resources/datapacks/biome-size/data/minecraft/worldgen/noise_settings/nether.json @@ -0,0 +1,737 @@ +{ + "aquifers_enabled": false, + "default_block": { + "Name": "minecraft:netherrack" + }, + "default_fluid": { + "Name": "minecraft:lava", + "Properties": { + "level": "0" + } + }, + "disable_mob_generation": false, + "legacy_random_source": true, + "noise": { + "height": 128, + "min_y": 0, + "size_horizontal": 1, + "size_vertical": 2 + }, + "noise_router": { + "barrier": 0, + "continents": 0, + "depth": 0, + "erosion": 0, + "final_density": { + "type": "minecraft:squeeze", + "argument": { + "type": "minecraft:mul", + "argument1": 0.64, + "argument2": { + "type": "minecraft:interpolated", + "argument": { + "type": "minecraft:blend_density", + "argument": { + "type": "minecraft:add", + "argument1": 2.5, + "argument2": { + "type": "minecraft:mul", + "argument1": { + "type": "minecraft:y_clamped_gradient", + "from_value": 0, + "from_y": -8, + "to_value": 1, + "to_y": 24 + }, + "argument2": { + "type": "minecraft:add", + "argument1": -2.5, + "argument2": { + "type": "minecraft:add", + "argument1": 0.9375, + "argument2": { + "type": "minecraft:mul", + "argument1": { + "type": "minecraft:y_clamped_gradient", + "from_value": 1, + "from_y": 104, + "to_value": 0, + "to_y": 128 + }, + "argument2": { + "type": "minecraft:add", + "argument1": -0.9375, + "argument2": "minecraft:nether/base_3d_noise" + } + } + } + } + } + } + } + } + } + }, + "fluid_level_floodedness": 0, + "fluid_level_spread": 0, + "initial_density_without_jaggedness": 0, + "lava": 0, + "ridges": 0, + "temperature": { + "type": "minecraft:shifted_noise", + "noise": "minecraft:temperature", + "shift_x": "minecraft:shift_x", + "shift_y": 0, + "shift_z": "minecraft:shift_z", + "xz_scale": 0.5, + "y_scale": 0 + }, + "vegetation": { + "type": "minecraft:shifted_noise", + "noise": "minecraft:vegetation", + "shift_x": "minecraft:shift_x", + "shift_y": 0, + "shift_z": "minecraft:shift_z", + "xz_scale": 0.5, + "y_scale": 0 + }, + "vein_gap": 0, + "vein_ridged": 0, + "vein_toggle": 0 + }, + "ore_veins_enabled": false, + "sea_level": 32, + "spawn_target": [], + "surface_rule": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:vertical_gradient", + "false_at_and_above": { + "above_bottom": 5 + }, + "random_name": "minecraft:bedrock_floor", + "true_at_and_below": { + "above_bottom": 0 + } + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:bedrock" + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:vertical_gradient", + "false_at_and_above": { + "below_top": 0 + }, + "random_name": "minecraft:bedrock_roof", + "true_at_and_below": { + "below_top": 5 + } + } + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:bedrock" + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": false, + "anchor": { + "below_top": 5 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:netherrack" + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:biome", + "biome_is": [ + "minecraft:basalt_deltas" + ] + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": true, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "ceiling" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:basalt", + "Properties": { + "axis": "y" + } + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": true, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "floor" + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": -0.012, + "noise": "minecraft:patch" + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 30 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 35 + }, + "surface_depth_multiplier": 0 + } + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:gravel" + } + } + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 0, + "noise": "minecraft:nether_state_selector" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:basalt", + "Properties": { + "axis": "y" + } + } + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:blackstone" + } + } + ] + } + } + ] + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:biome", + "biome_is": [ + "minecraft:soul_sand_valley" + ] + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": true, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "ceiling" + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 0, + "noise": "minecraft:nether_state_selector" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:soul_sand" + } + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:soul_soil" + } + } + ] + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": true, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "floor" + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": -0.012, + "noise": "minecraft:patch" + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 30 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 35 + }, + "surface_depth_multiplier": 0 + } + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:gravel" + } + } + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 0, + "noise": "minecraft:nether_state_selector" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:soul_sand" + } + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:soul_soil" + } + } + ] + } + } + ] + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": false, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "floor" + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:y_above", + "add_stone_depth": false, + "anchor": { + "absolute": 32 + }, + "surface_depth_multiplier": 0 + } + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:hole" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:lava", + "Properties": { + "level": "0" + } + } + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:biome", + "biome_is": [ + "minecraft:warped_forest" + ] + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 0.54, + "noise": "minecraft:netherrack" + } + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": false, + "anchor": { + "absolute": 31 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 1.17, + "noise": "minecraft:nether_wart" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:warped_wart_block" + } + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:warped_nylium" + } + } + ] + } + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:biome", + "biome_is": [ + "minecraft:crimson_forest" + ] + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 0.54, + "noise": "minecraft:netherrack" + } + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": false, + "anchor": { + "absolute": 31 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": 1.17, + "noise": "minecraft:nether_wart" + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:nether_wart_block" + } + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:crimson_nylium" + } + } + ] + } + } + } + } + ] + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:biome", + "biome_is": [ + "minecraft:nether_wastes" + ] + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": true, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "floor" + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": -0.012, + "noise": "minecraft:soul_sand_layer" + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:hole" + } + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 30 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 35 + }, + "surface_depth_multiplier": 0 + } + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:soul_sand" + } + } + } + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:netherrack" + } + } + ] + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:stone_depth", + "add_surface_depth": false, + "offset": 0, + "secondary_depth_range": 0, + "surface_type": "floor" + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": false, + "anchor": { + "absolute": 31 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:y_above", + "add_stone_depth": true, + "anchor": { + "absolute": 35 + }, + "surface_depth_multiplier": 0 + } + }, + "then_run": { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:noise_threshold", + "max_threshold": 1.7976931348623157e+308, + "min_threshold": -0.012, + "noise": "minecraft:gravel_layer" + }, + "then_run": { + "type": "minecraft:sequence", + "sequence": [ + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:y_above", + "add_stone_depth": false, + "anchor": { + "absolute": 32 + }, + "surface_depth_multiplier": 0 + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:gravel" + } + } + }, + { + "type": "minecraft:condition", + "if_true": { + "type": "minecraft:not", + "invert": { + "type": "minecraft:hole" + } + }, + "then_run": { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:gravel" + } + } + } + ] + } + } + } + } + } + ] + } + }, + { + "type": "minecraft:block", + "result_state": { + "Name": "minecraft:netherrack" + } + } + ] + } +} diff --git a/src/main/resources/datapacks/biome-size/pack.mcmeta b/src/main/resources/datapacks/biome-size/pack.mcmeta new file mode 100644 index 0000000..ba4783e --- /dev/null +++ b/src/main/resources/datapacks/biome-size/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 61, + "description": "" + } +} diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml new file mode 100644 index 0000000..6fb0e86 --- /dev/null +++ b/src/main/resources/paper-plugin.yml @@ -0,0 +1,7 @@ +name: MinecraftBingo +version: '1.12.0' +main: com.extremelyd1.main.Bingo +description: Item bingo in Minecraft +api-version: '1.21.4' +bootstrapper: com.extremelyd1.main.BingoBootstrap +load: STARTUP \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml deleted file mode 100644 index 20b9b68..0000000 --- a/src/main/resources/plugin.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: MinecraftBingo -version: 1.12.0 -main: com.extremelyd1.main.Bingo -author: Extremelyd1 -load: STARTUP -api-version: 1.17 - -commands: - team: - description: Command for handling teams - usage: / - - start: - description: Command to start the game - usage: / - - end: - description: Command to forcefully end the game - usage: / - - bingo: - description: Command to output items left/collected on bingo card - usage: / - - card: - description: Command to get a new bingo card if lost - usage: / - - pvp: - description: Command to toggle PVP - usage: / - - maintenance: - description: Command to toggle maintenance mode - usage: / - - wincondition: - aliases: [wincon] - description: Command to change win conditions, such as enabling full card mode - usage: / [argument] - - reroll: - description: Command to reroll the bingo card - usage: / - - itemdistribution: - aliases: [itemdist, distribution, dist] - description: Command to change the item distribution - usage: / - - timer: - description: Command to set the max timer length - usage: / - - coordinates: - aliases: [coord, coords] - description: Command to send your coordinates to your teammates - usage: / - - all: - aliases: [a, g, global] - description: Command to send a message to all players - usage: / - - teamchat: - aliases: [tc] - description: Send a message to your team only - usage: / - - test: - description: Command to test a new feature - usage: / - - channel: - aliases: [c] - description: Change between default chat channels - usage: / - - join: - description: Join a team - usage: / - - generate: - aliases: [worlds, gen] - description: Pre-generate worlds - usage: / stop | \ No newline at end of file