I am having trouble with my plugin. The error is "Cannot find main class 'turtdle.abilities.Main'" (I know I spelled turtle wrong, but it is my username.)
This plugin is for my server. I have already tried completing the plugin.yml file (with author, version, etc.) I also tried changing the plugin name to "Main." I have also tried moving the yml around with no success.
package turtdle.abilities;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin{
public Permission playerPermission1 = new Permission("turtdle.abilities.get");
public Permission playerPermission2 = new Permission("turtdle.place.bedrock");
#Override
public void onEnable() {
getLogger().info("onEnable Has been enabled for abilities plugin! BOOP!");
new PlayerListener(this);
new BlockRestricter(this);
PluginManager pm = getServer().getPluginManager();
pm.addPermission(playerPermission1);
pm.addPermission(playerPermission2);
}
#Override
public void onDisable() {
getLogger().info("onDisable Has been triggered for abilities plugin");
}
public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) {
if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player) {
Player player = (Player) sender;
player.sendMessage("Hewwooo, " + player.getName());
return true;
}
return false;
}
}
package turtdle.abilities;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
public class PlayerListener implements Listener{
public PlayerListener(Main plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
#EventHandler
public void onDeath (PlayerDeathEvent e) {
Player player = e.getEntity();
if (!player.hasPermission("turtdle.abilities.get")) {
player.sendMessage(ChatColor.AQUA + "OOF");
}
else {
{
player.sendMessage(ChatColor.AQUA + "you should've abused...");
}
}
}
}
package turtdle.abilities;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class BlockRestricter implements Listener{
public BlockRestricter(Main plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
#EventHandler
public void onBlockPlace (BlockPlaceEvent e) {
Player player = e.getPlayer();
Block block = e.getBlock();
if (!player.hasPermission("turtdle.place.bedrock") && block.getType().getId() == 7) {
player.sendMessage(ChatColor.RED + "You CAN'T PLACE THIS " + ChatColor.BOLD + "BLOCK! " + ChatColor.RESET + ChatColor.RED + " it is ILLEGAL");
e.setCancelled(true);
}
}
}
plugin.yml:
main: turtdle.abilities.Main
name: TurtdleAbilitiesCore
version: 0.2.9
author: CakeyTheTurtdle
description: ExclusiveWolfHuntplugin
commands:
hello:
description: When you're lonely
usage: /hello
Hey here is my whole error
https://pastebin.com/FAieE0Lr
The other answer is not correct, unfortunately.
In the Pastebin you linked, we can see that the error is the following:
Caused by: java.lang.ClassNotFoundException: turtdle.Main
When Bukkit is trying to load your main class, it is looking for the class turtdle.Main. The reason this is strange is your plugin.yml tells it to look for turtdle.abilities.Main, which it is not doing.
My guess for the cause of the issue is that sometimes when the project is being compiled, your IDE may not actually grab the edited plugin.yml file to put in the final jar. To fix this, complete the following steps:
Open your project folder and delete any/all of the following files/folders if they exist:
bin/
target/
YourPluginName.jar
Go to your server's folder and delete YourPluginName.jar there as well
Recompile your project and add the fresh jar file to your plugins folder.
Hopefully, this should resolve the issue. Your plugin.yml file and code both look fine and in theory should work. This is the only thing I can think of that would cause the issue.
Best of luck!
Related
I'm basically making a spigot plugin, for practice.
The server doesn't enable the server, no error in the console. It also no "INFO" for enabling the plugin.
This is my main class
package me.FarrosGaming.SpawnPillager;
import org.bukkit.plugin.java.JavaPlugin;
import me.FarrosGaming.SpawnPillager.commands.PillagerCommand;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
new PillagerCommand(this);
}
#Override
public void onDisable() {
}
}
This is my command class
package me.FarrosGaming.SpawnPillager.commands;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import me.FarrosGaming.SpawnPillager.Main;
public class PillagerCommand implements CommandExecutor {
private Main plugin;
public PillagerCommand(Main plugin) {
this.plugin = plugin;
plugin.getCommand("chase").setExecutor(this);
}
#Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players who can send this command.");
return true;
}
Player player = (Player) sender;
if (player.hasPermission("hello.use")) {
Location location = player.getLocation();
World world = player.getWorld();
for (int i = 0; i < 10; i++) {
world.spawnEntity(location, EntityType.CREEPER);
}
return true;
} else {
player.sendMessage("You do not have a permission to use this command");
}
return false;
}
}
this is my plugin.yml file
name: SpawnPillager
version: 1.0
author: FarrosGaming
description: blabla
main: me.FarrosGaming.SpawnPillager.Main
commands:
chase:
description: Spawn pillager in your location
usage: /chase
Literally, there are no spaces in the plugin.yml
I'm using the newest version of spigot.
make sure you are dropping your plugin's Jar in the right spot, i mean the right server's plugins folder, if you multiple and then reload/ restart your server,
I m telling this coz, me myself, have done this mistake too..
So I have double and triple checked my YML and ran it through a validator. My plugins load up fine, I can create a hello world command within my Main class that works. However upon using a second .java file with a second command it continuously displays my YML usage text.
Main.java
package lordfluffyjr.TarrenCraft.jEssentialsX.commandSrc;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener { //Extending JavaPlugin so that Bukkit
knows its the main class
//Housekeeping
Logger jEssentialsXLogger = Bukkit.getLogger();
#Override
public void onEnable(){// Where plugins will be loaded.
PluginManager manager = getServer().getPluginManager();
manager.registerEvents(this, this);
Bukkit.getServer().getConsoleSender().sendMessage("jEssentialsX has been enabled!");
//Enable FAQ
manager.registerEvents(new Faq(), this);
Bukkit.getServer().getConsoleSender().sendMessage("FAQ has been enabled!");
}
#Override
public void onDisable(){// Where plugins will be disabled.
jEssentialsXLogger.info("Test 1 has been disabled!");
jEssentialsXLogger.severe("Test 1 has an error and has not loaded.");
}
}
Faq.java
package lordfluffyjr.TarrenCraft.jEssentialsX.commandSrc;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
public class Faq implements Listener, CommandExecutor{
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
if (commandLabel.equalsIgnoreCase("faq")) {
sender.sendMessage("Welcome to our FAQ!");
return true;
}
return false;
}
}
plugin.yml
main: lordfluffyjr.TarrenCraft.jEssentialsX.commandSrc.Main
name: jEssentialsX
version: 0.1
author: LordFluffyJr
api-version: 1.16
commands:
faq:
description: A list of our frequently asked questions plugin description!
usage: Syntax error! Use [/faq <topic> <page number>]
You're not registering the Faq class as the command executor. You need to set it with
Bukkit.getPluginCommand("faq").setExecutor(- Faq class instance-);
I have made a plugin that is supposed to track the amount of diamonds you have mined in Minecraft and save it to a config.yml file. But my code doesn't seem to be working and I cant figure out why?
I've already tried +1 in the setConfig args and now I've switched over to this and it still doesn't seem to be working. I also have diamonds predefined in my config.yml file.
package com.raidoxe.BlockPlugin;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
getLogger().info("Sartu has been enabled :)");
PluginManager pm = getServer().getPluginManager();
SartuListener listener = new SartuListener(this);
pm.registerEvents(listener, this);
this.getConfig().options().copyDefaults(true);
this.saveConfig();
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (sender instanceof Player) {
String lowerCmd = cmd.getName().toLowerCase();
switch (lowerCmd) {
case "mydiamonds":
int a = this.getConfig().getInt("diamonds."+player.getUniqueId());
player.sendMessage(ChatColor.DARK_PURPLE+"You have mined "+ChatColor.RED+a+ChatColor.AQUA+" Diamonds");
return true;
}
}
return true;
}
------------Listener File-----------
package com.raidoxe.BlockPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
public class SartuListener implements Listener {
private Plugin plugin = Main.getPlugin(Main.class);
public SartuListener(Main plugin) {
}
#EventHandler
public void blockBreak(BlockBreakEvent event) {
Player player = (Player) event.getPlayer();
Block block = event.getBlock();
Material blockMaterial = block.getType();
if(blockMaterial.equals(Material.DIAMOND_ORE)) {
Bukkit.broadcastMessage(ChatColor.WHITE+player.getDisplayName()+" found a "+ ChatColor.AQUA + ChatColor.BOLD+"Diamond!!!");
int a = plugin.getConfig().getInt("diamonds."+player.getUniqueId());
plugin.getConfig().set("diamonds."+player.getUniqueId(), a++);
plugin.saveConfig();
}
}
when the player does the command /mydiamonds it should print out, "you have mined (a) diamonds". But it always prints out zero, no matter how many diamonds you have mined.
Your code seems to be looking fine except one minor mistake. You say that you've tried +1 in the setConfig, so if this solution does not work for you it's probably a version thing
If a config getInt() returns 0 it can mean two things:
value does not exist (default is returned)
value is actually 0 in the config
Upon testing the value does exist in the config (due to saveConfig(), but is set to 0. So this lead me to the setting method.
The issue is the adding part. You do a++ inside the method, this will increment the number after the method, we want before, switch to ++a. See this post.
if(blockMaterial.equals(Material.DIAMOND_ORE)) {
Bukkit.broadcastMessage(ChatColor.WHITE+player.getDisplayName()+" found a "+ ChatColor.AQUA + ChatColor.BOLD+"Diamond!!!");
int a = plugin.getConfig().getInt("diamonds."+player.getUniqueId());
plugin.getConfig().set("diamonds."+player.getUniqueId(), ++a);
plugin.saveConfig();
}
So, I recently started learning Java and BukkitAPI. I make a config file, and I make a class for player events, but then I can't register the events in my main class. I get an error "The method PlayerJoin(OnStartup) is undefined for the type OnStartup" and the only fix is to make a method. Here is my code:
OnStartup(main class):
package ml.zonia.plugin;
import java.io.File;
import java.util.logging.Logger;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import ml.zonia.plugin.commands.Potion;
import ml.zonia.plugin.event.PlayerJoin;
public class OnStartup extends JavaPlugin implements Listener {
public void onEnable() {
registerEvents();
registerConfig();
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
getServer().getPluginManager().registerEvents(this, this);
getCommand("zonia").setExecutor(new Potion());
logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
}
public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
//here is the error on PlayerJoin:The method PlayerJoin(OnStartup) is undefined for the type OnStartup
pm.registerEvents(PlayerJoin(this), this);
}
private void registerConfig() {
getConfig().options().copyDefaults(true);
saveConfig();
}
public void onDisable() {
PluginDescriptionFile pdfFile = getDescription();
Logger logger = getLogger();
logger.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled.");
saveConfig();
}
}
Potion Class(Just in case):
package ml.zonia.plugin.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public class Potion implements CommandExecutor, Listener {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("zonia"))
;
if (!(sender instanceof Player)) {
sender.sendMessage("You must be in-game to execute this command.");
return false;
}
Player player = (Player) sender;
player.sendMessage(ChatColor.DARK_AQUA + "ZoniaCore, made by Patrick S.");
return true;
}
}
PlayerJoin:
package ml.zonia.plugin.event;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import ml.zonia.plugin.OnStartup;
public class PlayerJoin implements Listener {
private OnStartup plugin;
public PlayerJoin(OnStartup pl) {
plugin = pl;
}
#EventHandler
public void onJoin(PlayerJoinEvent pje) {
int PlayerSpeed;
PlayerSpeed = plugin.getConfig().getInt("PlayerSpeed");
if (!pje.getPlayer().hasPermission("zonia.effects.remove"))
;
pje.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, PlayerSpeed));
}
#EventHandler
public void onPlayerMove(PlayerMoveEvent pme) {
double SpawnX, SpawnY, SpawnZ;
SpawnX = plugin.getConfig().getDouble("SpawnX");
SpawnY = plugin.getConfig().getDouble("SpawnY");
SpawnZ = plugin.getConfig().getDouble("SpawnZ");
if ((int) pme.getPlayer().getLocation().getY() == 20) {
pme.getPlayer().teleport(new Location(Bukkit.getWorld("world"), SpawnX, SpawnY, SpawnZ));
}
}
}
In eclipse, the config yml looks like this:
################################
# #
# ZoniaCore-Hub Config #
# Version 1.0 #
# #
################################
#Sets the player's speed.
PlayerSpeed: 17
#sets X, Y, and Z of spawn.
SpawnX: -67.5
SpawnY: 156
SpawnZ: 4.5
#sets how much the player has to fall
#to be teleported back to spawn.
TeleportY: 50
But when it generates in the plugins folder under the plugin it generates the config like this, and I cant seem to make any changes to it.:
#
# #
# ZoniaCore-Hub Config #
# Version 1.0 #
# #
PlayerSpeed: 6
SpawnX: -67.5
SpawnY: 156
SpawnZ: 4.5
TeleportY: 50
You probably mean:
pm.registerEvents(new PlayerJoin(this), this);
I don't see a PlayerJoin function, only the constructor. BTW it would be a bad practice to start a function name with capital letter, unless it's the constructor.
I have been trying to make a gun game plugin but I can't get the on player death event to work. The plugin loads just fine but when I kill another player nothing happens.
package me.GunGame;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin implements Listener {
#
Override
public void onEnable() {
getLogger().info("Gun Game Enabled");
}#
Override
public void onDisable() {
getLogger().info("Gun Game Disabled");
}
#
EventHandler
public void OnPlayerDeath(PlayerDeathEvent e) {
Player p = e.getEntity();
p.sendMessage(ChatColor.RED + "You have died!");
Player k = p.getKiller();
k.sendMessage(ChatColor.RED + "You killed " + p.getDisplayName());
}
}
You need to register your plugin for receiving the events. Use getServer().getPluginManager().registerEvents to register. See Event API Reference for more details.
You have to add to the onEnable()
You didn't register your event.
#Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
getLogger().info("Gun Game Enabled");
}
Simple mistake, people downvoted because if you read over your code, you would have seen that. Also it mentions it multiple times on the wiki.