ShadowKALler7
Member
so I got an idea to make type of a block shuffle for me and my cousin, I tried methods and it gives me this error:
[FATAL] Unhandled exception executing command "blockshufflestart" in blockshufflestart: java.lang.ClassCastException: class cn.nukkit.command.ConsoleCommandSender cannot be cast to class cn.nukkit.Player (cn.nukkit.command.ConsoleCommandSender and cn.nukkit.Player are in unnamed module of loader 'app')
at me.savage.slayer.block.shuffle.BlockShuffle.onCommand(BlockShuffle.java:31)
at cn.nukkit.command.PluginCommand.execute(PluginCommand.java:33)
at cn.nukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:257)
at cn.nukkit.Server.dispatchCommand(Server.java:764)
at cn.nukkit.console.NukkitConsole.lambda$runCommand$0(NukkitConsole.java:35)
at cn.nukkit.scheduler.TaskHandler.run(TaskHandler.java:99)
at cn.nukkit.scheduler.ServerScheduler.runTasks(ServerScheduler.java:296)
at cn.nukkit.scheduler.ServerScheduler.mainThreadHeartbeat(ServerScheduler.java:277)
at cn.nukkit.Server.tick(Server.java:1145)
at cn.nukkit.Server.tickProcessor(Server.java:916)
at cn.nukkit.Server.start(Server.java:893)
at cn.nukkit.Server.<init>(Server.java:578)
at cn.nukkit.Nukkit.main(Nukkit.java:112)
10:05:23 [ERROR] Throwing
java.lang.ClassCastException: class cn.nukkit.command.ConsoleCommandSender cannot be cast to class cn.nukkit.Player (cn.nukkit.command.ConsoleCommandSender and cn.nukkit.Player are in unnamed module of loader 'app')
at me.savage.slayer.block.shuffle.BlockShuffle.onCommand(BlockShuffle.java:31) ~[?:?]
at cn.nukkit.command.PluginCommand.execute(PluginCommand.java:33) ~[nukkit.jar:?]
at cn.nukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:257) ~[nukkit.jar:?]
at cn.nukkit.Server.dispatchCommand(Server.java:764) ~[nukkit.jar:?]
at cn.nukkit.console.NukkitConsole.lambda$runCommand$0(NukkitConsole.java:35) ~[nukkit.jar:?]
at cn.nukkit.scheduler.TaskHandler.run(TaskHandler.java:99) [nukkit.jar:?]
at cn.nukkit.scheduler.ServerScheduler.runTasks(ServerScheduler.java:296) [nukkit.jar:?]
at cn.nukkit.scheduler.ServerScheduler.mainThreadHeartbeat(ServerScheduler.java:277) [nukkit.jar:?]
at cn.nukkit.Server.tick(Server.java:1145) [nukkit.jar:?]
at cn.nukkit.Server.tickProcessor(Server.java:916) [nukkit.jar:?]
at cn.nukkit.Server.start(Server.java:893) [nukkit.jar:?]
at cn.nukkit.Server.<init>(Server.java:578) [nukkit.jar:?]
at cn.nukkit.Nukkit.main(Nukkit.java:112) [nukkit.jar:?]
my whole code:
package me.savage.slayer.block.shuffle;
import java.util.Random;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.block.Block;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.event.Listener;
import cn.nukkit.level.Position;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.scheduler.NukkitRunnable;
import cn.nukkit.utils.TextFormat;
public class BlockShuffle extends PluginBase implements Listener {
private boolean stopped;
private Random r;
String m;
int t = 300;
@Override
public void onEnable() {
this.getLogger().info(TextFormat.GREEN + BlockShuffle loaded! use BlockShuffleStart and BlockShuffleStop");
this.getServer().getPluginManager().registerEvents(this, this);
stopped = false;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player p = (Player) sender;
if (cmd.getName().equalsIgnoreCase("BlockShuffleStart")) {
if (stopped == true) {
sender.sendMessage(TextFormat.RED + "BlockShuffle is Already started!");
return true;
}
stopped = true;
sender.sendMessage(TextFormat.BLUE + "BlockShuffle Started!");
startblock(p);
}else if (cmd.getName().equalsIgnoreCase("BlockShuffleStop")) {
if (stopped == false) {
sender.sendMessage(TextFormat.RED + "BlockShuffle is already stopped!");
return true;
}
stopped = false;
sender.sendMessage(TextFormat.GOLD + "BlockShuffle stopped!");
}else if (cmd.getName().equalsIgnoreCase("BlockShuffleStatus")) {
if (stopped == false) {
sender.sendMessage(TextFormat.RED + "Off");
return true;
}else if (stopped == true) {
sender.sendMessage(TextFormat.GREEN + "On");
}
}
return false;
}
private void nextBlock(Player p) {
int y = this.r.nextInt(245);
if (y == 1) {
m = "a";
acaciadoor(p);
}
if (y == 2) {
m = "b";
acaciastairs(p);
}
if (y == 3) {
m = "c";
ActivatorRail(p);
}
if (y == 4) {
m = "d";
Anvil(p);
}
if (y == 5) {
m = "e";
Beacon(p);
}
if (y == 6) {
m = "f";
Bed(p);
}
if (y == 7) {
m = "g";
bedrock(p);
}
if (y == 8) {
m = "h";
birchDoor(p);
}
if (y == 9) {
m = "i";
birchStairs(p);
}
if (y == 10) {
m = "j";
blackGlazedTerracotta(p);
}
if (y == 11) {
m = "k";
netherWartBlock(p);
}
if (y == 12) {
m = "l";
blueGlazedTerracotta(p);
}
if (y == 13) {
m = "m";
boneBlock(p);
}
if (y == 14) {
m = "n";
bookshelf(p);
}
if (y == 15) {
m = "o";
brickStairs(p);
}
if (y == 16) {
m = "p";
brickBlock(p);
}
if (y == 17) {
m = "q";
brownGlazedTerracotta(p);
}
if (y == 18) {
m = "r";
brownMushroomBlock(p);
}
if (y == 19) {
m = "s";
cactus(p);
}
if (y == 20) {
m = "t";
cake(p);
}
}
private void startblock(Player p) {
int y = this.r.nextInt(245);
if (y == 1) {
m = "a";
acaciadoor(p);
}
if (y == 2) {
m = "b";
acaciastairs(p);
}
if (y == 3) {
m = "c";
ActivatorRail(p);
}
if (y == 4) {
m = "d";
Anvil(p);
}
if (y == 5) {
m = "e";
Beacon(p);
}
if (y == 6) {
m = "f";
Bed(p);
}
if (y == 7) {
m = "g";
bedrock(p);
}
if (y == 8) {
m = "h";
birchDoor(p);
}
if (y == 9) {
m = "i";
birchStairs(p);
}
if (y == 10) {
m = "j";
blackGlazedTerracotta(p);
}
if (y == 11) {
m = "k";
netherWartBlock(p);
}
if (y == 12) {
m = "l";
blueGlazedTerracotta(p);
}
if (y == 13) {
m = "m";
boneBlock(p);
}
if (y == 14) {
m = "n";
bookshelf(p);
}
if (y == 15) {
m = "o";
brickStairs(p);
}
if (y == 16) {
m = "p";
brickBlock(p);
}
if (y == 17) {
m = "q";
brownGlazedTerracotta(p);
}
if (y == 18) {
m = "r";
brownMushroomBlock(p);
}
if (y == 19) {
m = "s";
cactus(p);
}
if (y == 20) {
m = "t";
cake(p);
}
}
private void acaciadoor(Player p) {
if (m != "a") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "Acacia door");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACACIA_DOOR_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ACACIA_DOOR_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
}
}
}
}
private void acaciastairs(Player p) {
if (m != "b") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "Acacia stairs");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACACIA_WOOD_STAIRS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ACACIA_WOOD_STAIRS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void ActivatorRail(Player p) {
if (m != "c") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "Activator Rail");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACTIVATOR_RAIL) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ACTIVATOR_RAIL) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void Anvil(Player p) {
if (m != "d") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "anvil");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ANVIL) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ANVIL) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void Beacon(Player p) {
if (m != "e") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "beacon");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BEACON) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BEACON) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void Bed(Player p) {
if (m != "f") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bed");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BED_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BED_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void bedrock(Player p) {
if (m != "g") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bedrock");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BEDROCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BEDROCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void birchDoor(Player p) {
if (m != "h") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "birch door");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BIRCH_DOOR_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BIRCH_DOOR_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void birchStairs(Player p) {
if (m != "i") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "birch stairs");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BIRCH_WOOD_STAIRS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BIRCH_WOOD_STAIRS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void blackGlazedTerracotta(Player p) {
if (m != "j") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "black glazed terracotta (good luck)");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BLACK_GLAZED_TERRACOTTA) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BLACK_GLAZED_TERRACOTTA) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void netherWartBlock(Player p) {
if (m != "k") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "nether wart block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BLOCK_NETHER_WART_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BLOCK_NETHER_WART_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void blueGlazedTerracotta(Player p) {
if (m != "l") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "blue glazed terracotta");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BLUE_GLAZED_TERRACOTTA) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BLUE_GLAZED_TERRACOTTA) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void boneBlock(Player p) {
if (m != "m") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bone block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BONE_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BONE_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void bookshelf(Player p) {
if (m != "n") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bookshelf");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BOOKSHELF) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BOOKSHELF) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brickStairs(Player p) {
if (m != "o") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brick stairs");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BRICK_STAIRS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BRICK_STAIRS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brickBlock(Player p) {
if (m != "p") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brick block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BRICKS_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BRICKS_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brownGlazedTerracotta(Player p) {
if (m != "q") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brown glazed terracotta");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BROWN_GLAZED_TERRACOTTA) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BROWN_GLAZED_TERRACOTTA) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brownMushroomBlock(Player p) {
if (m != "r") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brown mushroom block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BROWN_MUSHROOM_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BROWN_MUSHROOM_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void cactus(Player p) {
if (m != "s") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "cactus");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CACTUS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CACTUS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void cake(Player p) {
if (m != "t") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "cake");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CAKE_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CAKE_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void carpet(Player p) {
if (m != "u") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "carpet");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CARPET) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CARPET) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void cauldron(Player p) {
if (m != "v") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "cauldron");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CAULDRON_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CAULDRON_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void chest(Player p) {
if (m != "w") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "chest");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CHEST) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CHEST) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void chorusFlower(Player p) {
if (m != "x") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "chorus flower");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CHORUS_FLOWER) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CHORUS_FLOWER) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
}
should I try a catch method?
[FATAL] Unhandled exception executing command "blockshufflestart" in blockshufflestart: java.lang.ClassCastException: class cn.nukkit.command.ConsoleCommandSender cannot be cast to class cn.nukkit.Player (cn.nukkit.command.ConsoleCommandSender and cn.nukkit.Player are in unnamed module of loader 'app')
at me.savage.slayer.block.shuffle.BlockShuffle.onCommand(BlockShuffle.java:31)
at cn.nukkit.command.PluginCommand.execute(PluginCommand.java:33)
at cn.nukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:257)
at cn.nukkit.Server.dispatchCommand(Server.java:764)
at cn.nukkit.console.NukkitConsole.lambda$runCommand$0(NukkitConsole.java:35)
at cn.nukkit.scheduler.TaskHandler.run(TaskHandler.java:99)
at cn.nukkit.scheduler.ServerScheduler.runTasks(ServerScheduler.java:296)
at cn.nukkit.scheduler.ServerScheduler.mainThreadHeartbeat(ServerScheduler.java:277)
at cn.nukkit.Server.tick(Server.java:1145)
at cn.nukkit.Server.tickProcessor(Server.java:916)
at cn.nukkit.Server.start(Server.java:893)
at cn.nukkit.Server.<init>(Server.java:578)
at cn.nukkit.Nukkit.main(Nukkit.java:112)
10:05:23 [ERROR] Throwing
java.lang.ClassCastException: class cn.nukkit.command.ConsoleCommandSender cannot be cast to class cn.nukkit.Player (cn.nukkit.command.ConsoleCommandSender and cn.nukkit.Player are in unnamed module of loader 'app')
at me.savage.slayer.block.shuffle.BlockShuffle.onCommand(BlockShuffle.java:31) ~[?:?]
at cn.nukkit.command.PluginCommand.execute(PluginCommand.java:33) ~[nukkit.jar:?]
at cn.nukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:257) ~[nukkit.jar:?]
at cn.nukkit.Server.dispatchCommand(Server.java:764) ~[nukkit.jar:?]
at cn.nukkit.console.NukkitConsole.lambda$runCommand$0(NukkitConsole.java:35) ~[nukkit.jar:?]
at cn.nukkit.scheduler.TaskHandler.run(TaskHandler.java:99) [nukkit.jar:?]
at cn.nukkit.scheduler.ServerScheduler.runTasks(ServerScheduler.java:296) [nukkit.jar:?]
at cn.nukkit.scheduler.ServerScheduler.mainThreadHeartbeat(ServerScheduler.java:277) [nukkit.jar:?]
at cn.nukkit.Server.tick(Server.java:1145) [nukkit.jar:?]
at cn.nukkit.Server.tickProcessor(Server.java:916) [nukkit.jar:?]
at cn.nukkit.Server.start(Server.java:893) [nukkit.jar:?]
at cn.nukkit.Server.<init>(Server.java:578) [nukkit.jar:?]
at cn.nukkit.Nukkit.main(Nukkit.java:112) [nukkit.jar:?]
my whole code:
package me.savage.slayer.block.shuffle;
import java.util.Random;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.block.Block;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.event.Listener;
import cn.nukkit.level.Position;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.scheduler.NukkitRunnable;
import cn.nukkit.utils.TextFormat;
public class BlockShuffle extends PluginBase implements Listener {
private boolean stopped;
private Random r;
String m;
int t = 300;
@Override
public void onEnable() {
this.getLogger().info(TextFormat.GREEN + BlockShuffle loaded! use BlockShuffleStart and BlockShuffleStop");
this.getServer().getPluginManager().registerEvents(this, this);
stopped = false;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player p = (Player) sender;
if (cmd.getName().equalsIgnoreCase("BlockShuffleStart")) {
if (stopped == true) {
sender.sendMessage(TextFormat.RED + "BlockShuffle is Already started!");
return true;
}
stopped = true;
sender.sendMessage(TextFormat.BLUE + "BlockShuffle Started!");
startblock(p);
}else if (cmd.getName().equalsIgnoreCase("BlockShuffleStop")) {
if (stopped == false) {
sender.sendMessage(TextFormat.RED + "BlockShuffle is already stopped!");
return true;
}
stopped = false;
sender.sendMessage(TextFormat.GOLD + "BlockShuffle stopped!");
}else if (cmd.getName().equalsIgnoreCase("BlockShuffleStatus")) {
if (stopped == false) {
sender.sendMessage(TextFormat.RED + "Off");
return true;
}else if (stopped == true) {
sender.sendMessage(TextFormat.GREEN + "On");
}
}
return false;
}
private void nextBlock(Player p) {
int y = this.r.nextInt(245);
if (y == 1) {
m = "a";
acaciadoor(p);
}
if (y == 2) {
m = "b";
acaciastairs(p);
}
if (y == 3) {
m = "c";
ActivatorRail(p);
}
if (y == 4) {
m = "d";
Anvil(p);
}
if (y == 5) {
m = "e";
Beacon(p);
}
if (y == 6) {
m = "f";
Bed(p);
}
if (y == 7) {
m = "g";
bedrock(p);
}
if (y == 8) {
m = "h";
birchDoor(p);
}
if (y == 9) {
m = "i";
birchStairs(p);
}
if (y == 10) {
m = "j";
blackGlazedTerracotta(p);
}
if (y == 11) {
m = "k";
netherWartBlock(p);
}
if (y == 12) {
m = "l";
blueGlazedTerracotta(p);
}
if (y == 13) {
m = "m";
boneBlock(p);
}
if (y == 14) {
m = "n";
bookshelf(p);
}
if (y == 15) {
m = "o";
brickStairs(p);
}
if (y == 16) {
m = "p";
brickBlock(p);
}
if (y == 17) {
m = "q";
brownGlazedTerracotta(p);
}
if (y == 18) {
m = "r";
brownMushroomBlock(p);
}
if (y == 19) {
m = "s";
cactus(p);
}
if (y == 20) {
m = "t";
cake(p);
}
}
private void startblock(Player p) {
int y = this.r.nextInt(245);
if (y == 1) {
m = "a";
acaciadoor(p);
}
if (y == 2) {
m = "b";
acaciastairs(p);
}
if (y == 3) {
m = "c";
ActivatorRail(p);
}
if (y == 4) {
m = "d";
Anvil(p);
}
if (y == 5) {
m = "e";
Beacon(p);
}
if (y == 6) {
m = "f";
Bed(p);
}
if (y == 7) {
m = "g";
bedrock(p);
}
if (y == 8) {
m = "h";
birchDoor(p);
}
if (y == 9) {
m = "i";
birchStairs(p);
}
if (y == 10) {
m = "j";
blackGlazedTerracotta(p);
}
if (y == 11) {
m = "k";
netherWartBlock(p);
}
if (y == 12) {
m = "l";
blueGlazedTerracotta(p);
}
if (y == 13) {
m = "m";
boneBlock(p);
}
if (y == 14) {
m = "n";
bookshelf(p);
}
if (y == 15) {
m = "o";
brickStairs(p);
}
if (y == 16) {
m = "p";
brickBlock(p);
}
if (y == 17) {
m = "q";
brownGlazedTerracotta(p);
}
if (y == 18) {
m = "r";
brownMushroomBlock(p);
}
if (y == 19) {
m = "s";
cactus(p);
}
if (y == 20) {
m = "t";
cake(p);
}
}
private void acaciadoor(Player p) {
if (m != "a") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "Acacia door");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACACIA_DOOR_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ACACIA_DOOR_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
}
}
}
}
private void acaciastairs(Player p) {
if (m != "b") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "Acacia stairs");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACACIA_WOOD_STAIRS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ACACIA_WOOD_STAIRS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void ActivatorRail(Player p) {
if (m != "c") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "Activator Rail");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACTIVATOR_RAIL) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ACTIVATOR_RAIL) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void Anvil(Player p) {
if (m != "d") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "anvil");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ANVIL) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.ANVIL) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void Beacon(Player p) {
if (m != "e") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "beacon");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BEACON) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BEACON) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void Bed(Player p) {
if (m != "f") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bed");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BED_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BED_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void bedrock(Player p) {
if (m != "g") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bedrock");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BEDROCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BEDROCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void birchDoor(Player p) {
if (m != "h") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "birch door");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BIRCH_DOOR_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BIRCH_DOOR_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void birchStairs(Player p) {
if (m != "i") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "birch stairs");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BIRCH_WOOD_STAIRS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BIRCH_WOOD_STAIRS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void blackGlazedTerracotta(Player p) {
if (m != "j") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "black glazed terracotta (good luck)");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BLACK_GLAZED_TERRACOTTA) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BLACK_GLAZED_TERRACOTTA) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void netherWartBlock(Player p) {
if (m != "k") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "nether wart block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BLOCK_NETHER_WART_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BLOCK_NETHER_WART_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void blueGlazedTerracotta(Player p) {
if (m != "l") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "blue glazed terracotta");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BLUE_GLAZED_TERRACOTTA) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BLUE_GLAZED_TERRACOTTA) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void boneBlock(Player p) {
if (m != "m") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bone block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BONE_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BONE_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void bookshelf(Player p) {
if (m != "n") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "bookshelf");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BOOKSHELF) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BOOKSHELF) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brickStairs(Player p) {
if (m != "o") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brick stairs");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BRICK_STAIRS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BRICK_STAIRS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brickBlock(Player p) {
if (m != "p") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brick block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BRICKS_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BRICKS_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brownGlazedTerracotta(Player p) {
if (m != "q") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brown glazed terracotta");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BROWN_GLAZED_TERRACOTTA) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BROWN_GLAZED_TERRACOTTA) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void brownMushroomBlock(Player p) {
if (m != "r") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "brown mushroom block");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.BROWN_MUSHROOM_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.BROWN_MUSHROOM_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void cactus(Player p) {
if (m != "s") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "cactus");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CACTUS) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CACTUS) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void cake(Player p) {
if (m != "t") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "cake");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CAKE_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CAKE_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void carpet(Player p) {
if (m != "u") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "carpet");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CARPET) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CARPET) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void cauldron(Player p) {
if (m != "v") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "cauldron");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CAULDRON_BLOCK) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CAULDRON_BLOCK) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void chest(Player p) {
if (m != "w") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "chest");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CHEST) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CHEST) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
private void chorusFlower(Player p) {
if (m != "x") {
return;
}
Position l = p.getSpawn();
p.sendMessage(TextFormat.GOLD + "chorus flower");
new NukkitRunnable() {
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.CHORUS_FLOWER) {
nextBlock(p);
p.sendMessage(p.getName() + " has found their block! ");
return;
}
}
}.runTaskTimerAsynchronously(this, 1, 0);
for(;t >= 0; t--) {
if (t % 10==0 || t<10) {
p.sendMessage(t + "seconds until you can find your block!");
}
if (t == 0) {
if (p.subtract(0, 1, 0).getLevelBlock().getId() != Block.CHORUS_FLOWER) {
p.sendMessage(" you lose " + p.getName());
p.teleport(l);
return;
}
}
}
}
}
should I try a catch method?