code not working (null pointer exception)

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?
 
put this first:

if(!(sender instanceof Player))
return false;

in your onCommand to make it work

also, suggesting to put your code in https://hastebin.com/ because this is ugly to look at
I still get an error
[FATAL] Unhandled exception executing command "blockshufflestart" in blockshufflestart: java.lang.NullPointerException
at me.savage.slayer.block.shuffle.BlockShuffle.startblock(BlockShuffle.java:147)
at me.savage.slayer.block.shuffle.BlockShuffle.onCommand(BlockShuffle.java:43)
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.Player.handleDataPacket(Player.java:2812)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at cn.nukkit.network.Network.processPackets(Network.java:268)
at cn.nukkit.network.Network.processBatch(Network.java:251)
at cn.nukkit.Player.handleDataPacket(Player.java:2102)
at cn.nukkit.network.RakNetInterface.handleEncapsulated(RakNetInterface.java:156)
at cn.nukkit.raknet.server.ServerHandler.handlePacket(ServerHandler.java:132)
at cn.nukkit.network.RakNetInterface.process(RakNetInterface.java:65)
at cn.nukkit.network.Network.processInterfaces(Network.java:152)
at cn.nukkit.Server.tick(Server.java:1137)
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:53:11 [ERROR] Throwing
java.lang.NullPointerException: null
at me.savage.slayer.block.shuffle.BlockShuffle.startblock(BlockShuffle.java:147) ~[?:?]
at me.savage.slayer.block.shuffle.BlockShuffle.onCommand(BlockShuffle.java:43) ~[?:?]
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.Player.handleDataPacket(Player.java:2812) ~[nukkit.jar:?]
at java.util.ArrayList.forEach(ArrayList.java:1511) [?:?]
at cn.nukkit.network.Network.processPackets(Network.java:268) [nukkit.jar:?]
at cn.nukkit.network.Network.processBatch(Network.java:251) [nukkit.jar:?]
at cn.nukkit.Player.handleDataPacket(Player.java:2102) [nukkit.jar:?]
at cn.nukkit.network.RakNetInterface.handleEncapsulated(RakNetInterface.java:156) [nukkit.jar:?]
at cn.nukkit.raknet.server.ServerHandler.handlePacket(ServerHandler.java:132) [nukkit.jar:?]
at cn.nukkit.network.RakNetInterface.process(RakNetInterface.java:65) [nukkit.jar:?]
at cn.nukkit.network.Network.processInterfaces(Network.java:152) [nukkit.jar:?]
at cn.nukkit.Server.tick(Server.java:1137) [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:?]
 

Joshua CC

Member
this is honestly hard to fix anything because of its code itself is so long. I'm suggesting you to start from scratch, learn how to handle ArrayList, HashMaps and for loops because they will be your best uses for getting a collection of objects. They will help a lot for more readable and shorter lines of codes.
 
this is honestly hard to fix anything because of its code itself is so long. I'm suggesting you to start from scratch, learn how to handle ArrayList, HashMaps and for loops because they will be your best uses for getting a collection of objects. They will help a lot for more readable and shorter lines of codes.
ok thank you
 
I started from scratch again ans STILL I get an error, although I cant see anything wrong:
[FATAL] Could not pass event "cn.nukkit.event.player.PlayerMoveEvent" to "BlockShuffler v1.0": null on me.savage.slayer.blockshuffler.BlockShuffler
12:20:38 [ERROR] Throwing
cn.nukkit.utils.EventException: null
at cn.nukkit.plugin.MethodEventExecutor.execute(MethodEventExecutor.java:34) ~[nukkit.jar:?]
at cn.nukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:56) ~[nukkit.jar:?]
at cn.nukkit.plugin.PluginManager.callEvent(PluginManager.java:543) [nukkit.jar:?]
at cn.nukkit.Player.processMovement(Player.java:1543) [nukkit.jar:?]
at cn.nukkit.Player.onUpdate(Player.java:1685) [nukkit.jar:?]
at cn.nukkit.level.Level.doTick(Level.java:824) [nukkit.jar:?]
at cn.nukkit.Server.checkTickUpdates(Server.java:1066) [nukkit.jar:?]
at cn.nukkit.Server.tick(Server.java:1148) [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:?]
Caused by: java.lang.NullPointerException
at me.savage.slayer.blockshuffler.BlockShuffler.onBlockShuffle(BlockShuffler.java:32) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
at cn.nukkit.plugin.MethodEventExecutor.execute(MethodEventExecutor.java:29) ~[nukkit.jar:?]
... 11 more
12:20:38 [FATAL] Could not pass event "cn.nukkit.event.player.PlayerMoveEvent" to "BlockShuffler v1.0": null on me.savage.slayer.blockshuffler.BlockShuffler

code:
package me.savage.slayer.blockshuffler;

import java.util.Random;

import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerMoveEvent;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.scheduler.NukkitRunnable;
import cn.nukkit.utils.TextFormat;

public class BlockShuffler extends PluginBase implements Listener{
private boolean stopped;
private Random r;
String m;
int t = 300;
private boolean is;

@Override
public void onEnable() {
this.getLogger().info(TextFormat.GREEN + "BlockShuffler loaded, use BlockShuffleStart and BlockShuffleStop");
stopped = false;
Random r = new Random();
this.getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onBlockShuffle(PlayerMoveEvent e) {

Player p = e.getPlayer();
int y = this.r.nextInt(3);

if (y == 1) {
if (is == false) {
return;
}
is = true;
p.sendMessage(TextFormat.YELLOW + "Acacia door");
}
new NukkitRunnable() {
@Override
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACACIA_DOOR_BLOCK) {
is = false;
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_DOOR_BLOCK) {
p.sendMessage(" you lose " + p.getName());

}
}
}
if (y == 2) {
if (is == true) {
return;
}
is = false;
p.sendMessage(TextFormat.YELLOW + "Acacia stairs");
}
new NukkitRunnable() {
@Override
public void run() {
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.ACACIA_WOOD_STAIRS) {
is = true;
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());

}
}
}
}
}
 
You can also use this for reference to help you much with the API of Nukkit, introducing Javadocs

ok I even tried a
try{
while (is == true){
if (p.subtract(0, 1, 0).getLevelBlock().getId() == Block.STONE){
p.sendMessage("stone")
is = false;
}
}
}catch (EventException error){
e.printStackTrace();
throw error;
}

i still get the error "Couldn't pass event to class"
 
Top