2023-08-24 09:43:16 +00:00
|
|
|
package dev.plex.extras.command;
|
2022-07-09 14:26:57 +00:00
|
|
|
|
2023-08-24 09:43:16 +00:00
|
|
|
import dev.plex.command.PlexCommand;
|
2022-07-09 14:26:57 +00:00
|
|
|
import dev.plex.command.annotation.CommandParameters;
|
|
|
|
import dev.plex.command.annotation.CommandPermissions;
|
|
|
|
import dev.plex.command.source.RequiredCommandSource;
|
|
|
|
import dev.plex.rank.enums.Rank;
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2023-03-08 19:30:51 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
2022-07-09 14:26:57 +00:00
|
|
|
@CommandParameters(name = "randomfish", description = "Spawns a random type of fish at your location", aliases = "rfish,bird")
|
|
|
|
@CommandPermissions(level = Rank.OP, permission = "plex.tfmextras.randomfish", source = RequiredCommandSource.IN_GAME)
|
|
|
|
public class RandomFishCommand extends PlexCommand
|
|
|
|
{
|
|
|
|
private static final List<EntityType> FISH_TYPES = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
|
|
|
{
|
2023-08-24 09:43:16 +00:00
|
|
|
@Nullable Block block = player.getTargetBlockExact(15);
|
2022-07-09 14:26:57 +00:00
|
|
|
if (block == null)
|
|
|
|
{
|
|
|
|
return MiniMessage.miniMessage().deserialize("<red>There is no block within 15 blocks of you.");
|
|
|
|
}
|
|
|
|
player.getWorld().spawnEntity(block.getLocation().add(0, 1, 0), randomFish());
|
|
|
|
return MiniMessage.miniMessage().deserialize(":goodbird:");
|
|
|
|
}
|
|
|
|
|
|
|
|
private EntityType randomFish()
|
|
|
|
{
|
|
|
|
return FISH_TYPES.get(ThreadLocalRandom.current().nextInt(FISH_TYPES.size()));
|
|
|
|
}
|
|
|
|
}
|