Minecraft Command not working

package org.main.main;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;

public class drillcommand implements CommandExecutor {


public static @NotNull String getInstance() {

return "";
}

@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(ChatColor.RED + "Only players can execute this command");

return true;
}

Player player = (Player) commandSender;
ItemStack customDrill = new ItemStack(Material.PRISMARINE_SHARD);
ItemMeta meta = customDrill.getItemMeta();

meta.setDisplayName(ChatColor.DARK_GREEN + "Personal Drill");
meta.setLore(Arrays.asList(
ChatColor.DARK_GRAY + "This drill was crafted from a special material found deep in the mines.",
ChatColor.DARK_GRAY + "That specific material allows the user to relocate their drill at any time.",
"",
ChatColor.LIGHT_PURPLE + "UNIQUE DRILL"));

meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.DENSITY, 1, false);

meta.getPersistentDataContainer().set(drill.CUSTOM_DIAMOND, PersistentDataType.BOOLEAN, true);

customDrill.setItemMeta(meta);

player.getInventory().addItem(customDrill);

return true;

}
}
package org.main.main;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;

public class drillcommand implements CommandExecutor {


public static @NotNull String getInstance() {

return "";
}

@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String @NotNull [] strings) {
if (!(commandSender instanceof Player)) {
commandSender.sendMessage(ChatColor.RED + "Only players can execute this command");

return true;
}

Player player = (Player) commandSender;
ItemStack customDrill = new ItemStack(Material.PRISMARINE_SHARD);
ItemMeta meta = customDrill.getItemMeta();

meta.setDisplayName(ChatColor.DARK_GREEN + "Personal Drill");
meta.setLore(Arrays.asList(
ChatColor.DARK_GRAY + "This drill was crafted from a special material found deep in the mines.",
ChatColor.DARK_GRAY + "That specific material allows the user to relocate their drill at any time.",
"",
ChatColor.LIGHT_PURPLE + "UNIQUE DRILL"));

meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.DENSITY, 1, false);

meta.getPersistentDataContainer().set(drill.CUSTOM_DIAMOND, PersistentDataType.BOOLEAN, true);

customDrill.setItemMeta(meta);

player.getInventory().addItem(customDrill);

return true;

}
}
No description
15 Replies
JavaBot
JavaBot2w ago
This post has been reserved for your question.
Hey @hii! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
hii
hiiOP2w ago
package org.main.main;

import org.bukkit.NamespacedKey;

public class drill {

public static final NamespacedKey CUSTOM_DIAMOND = new NamespacedKey(drillcommand.getInstance(), "Personal Drill");
}
package org.main.main;

import org.bukkit.NamespacedKey;

public class drill {

public static final NamespacedKey CUSTOM_DIAMOND = new NamespacedKey(drillcommand.getInstance(), "Personal Drill");
}
package org.main.main;

import org.bukkit.plugin.java.JavaPlugin;

import java.util.Objects;

public final class Main extends JavaPlugin {

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new listener(), this);
Objects.requireNonNull(getCommand("drill")).setExecutor(new drillcommand());

}

@Override
public void onDisable() {

}
}
package org.main.main;

import org.bukkit.plugin.java.JavaPlugin;

import java.util.Objects;

public final class Main extends JavaPlugin {

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new listener(), this);
Objects.requireNonNull(getCommand("drill")).setExecutor(new drillcommand());

}

@Override
public void onDisable() {

}
}
I am very new to java development regarding minecraft and I have no idea how to fix this and I would like some suggestions on what the issue could be. The plugin itself is functional in-game but the command just doesn't work, I'm suspecting that
public static @NotNull String getInstance() {

return "";
}
public static @NotNull String getInstance() {

return "";
}
might have a part in this issue but I do not know how it works or what to put in there. I also tried using the suggestions with the ''getInstance'' issue in the public class drill which had suggested me that part of the code.
ayylmao123xdd
ayylmao123xdd2w ago
can you show the error stacktrace that happens when it says unexpected error occurred
hii
hiiOP2w ago
Console?
hii
hiiOP2w ago
ayylmao123xdd
ayylmao123xdd2w ago
it says the namespace is invalid and it doesnt follow the regex
hii
hiiOP2w ago
So I can't use spaces?
ayylmao123xdd
ayylmao123xdd2w ago
try "a" and check if the error is different
hii
hiiOP2w ago
Works.
ayylmao123xdd
ayylmao123xdd2w ago
once you run it
hii
hiiOP2w ago
The issue is fixed.
hii
hiiOP2w ago
No description
hii
hiiOP2w ago
Thank you.
JavaBot
JavaBot2w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2w ago
Post Closed
This post has been closed by <@976202797173338143>.

Did you find this page helpful?