mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 09:15:38 +00:00
eb9759f2d8
SplittableRandom is faster (negligable) than Random and is also able to recursively return new instances of itself for an even more complex pseudo random generator compared to the default Random supplied by Java.
34 lines
1.2 KiB
Java
34 lines
1.2 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.SplittableRandom;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.EntityType;
|
|
import org.bukkit.entity.Player;
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
|
@CommandParameters(description = "Spawns a random type of fish at your location.", usage = "/<command>")
|
|
public class Command_bird extends FreedomCommand
|
|
{
|
|
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
{
|
|
Location location = playerSender.getTargetBlock(null, 15).getLocation().add(0, 1, 0);
|
|
playerSender.getWorld().spawnEntity(location, getRandomFish());
|
|
msg(":goodbird:");
|
|
return true;
|
|
}
|
|
|
|
public EntityType getRandomFish()
|
|
{
|
|
List<EntityType> fishTypes = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH);
|
|
SplittableRandom random = new SplittableRandom();
|
|
return fishTypes.get(random.nextInt(fishTypes.size()));
|
|
}
|
|
}
|