I recently started creating a small plugin for my Minecraft bukkit/spigot server (Minecraft Version 1.15.2) for sending the player a message with his coordinates upon death. Everything worked fine until I tried to implement a command for enabling and disabling this feature. For doing this I created a new java class, but when I tried to compile, I got this error:
Error:(9, 8) java: cannot find symbol
symbol: constructor CommandExecute()
location: class net.minecraft.server.v1_15_R1.CommandExecute
Since I am new to java I can't really think of something to fix this and therefore hope for your help! The entire code can be seen below (JDK 1.8):
package com.minecraft.deathmessage;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public class DeathMessage extends JavaPlugin {
private CommandsClass commands = new CommandsClass();
private final Server server = getServer();
public Boolean enabled = false;
public void onEnable() {
// Initialisation Message
server.getConsoleSender().sendMessage(
"[DM] " + ChatColor.GREEN + "DeathMessage plugin has been enabled");
// Event registering
server.getPluginManager().registerEvents(new EventsClass(), this);
// Command registering
Objects.requireNonNull(getCommand(commands.cmd_header)).setExecutor(commands);
}
public void onDisable() {
server.getConsoleSender().sendMessage(
"[DM] " + ChatColor.GREEN + "DeathMessage plugin has been disabled");
}
}
package com.minecraft.deathmessage;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
public class EventsClass implements Listener {
@EventHandler
public void onDeath(PlayerDeathEvent event) {
if (true) { // this is just a placeholder for later checking if the feature is enabled or not
Entity entity = event.getEntity();
String entity_type = entity.getType().toString();
if (entity_type.equals("PLAYER")) {
Location player_location = entity.getLocation();
int x_pos = (int) player_location.getX();
int y_pos = (int) player_location.getY();
int z_pos = (int) player_location.getZ();
World world = player_location.getWorld();
String world_string = ChatColor.GREEN + "overworld";
if (world != null) {
if (world.getName().equals("world_nether")) {
world_string = ChatColor.RED + "nether";
} else if (world.getName().equals("world_the_end")) {
world_string = ChatColor.BLUE + "end";
}
}
entity.sendMessage("[DC] " + ChatColor.GOLD + "You died at " + ChatColor.WHITE + Integer.toString(x_pos) +
" " + Integer.toString(y_pos) + " " + Integer.toString(z_pos) + ChatColor.GOLD + " in the " + ChatColor.WHITE +
world_string + ChatColor.GOLD + "!");
}
}
}
}
package com.minecraft.deathmessage;
import net.minecraft.server.v1_15_R1.CommandExecute;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
public class CommandsClass extends CommandExecute implements Listener, CommandExecutor {
public String cmd_header = "dm";
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return false;
}
}
I figured it out. There doesn't exist a constructor for the CommadExecute
class, so it cannot be extended (as far as I know). Since there is no neccesity in using CommandExecute
you can leave it out.