I am making a spigot mod with using a spigot jar and running that and I cannot import anything from org.bukkit
.
My plugin is supposed to give players random hearts when they join for the first time.
My code is:
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Random;
public class RandomHeartsPlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
int randomHearts = generateRandomHearts();
player.setHealth(randomHearts);
player.sendMessage("You have been given " + randomHearts + " extra hearts!");
}
private int generateRandomHearts() {
Random random = new Random();
// Generating a random number between 0 and 20 (inclusive)
return random.nextInt(21);
}
}
and I run it with the command:
javac plugins/RandomHeartsPlugin.java -cp bundler/libaries
I tried using -cp
wiht other things but I still can't compile it, I get:
plugins\RandomHeartsPlugin.java:3: error: package org.bukkit.entity does not exist
import org.bukkit.entity.Player;
^
plugins\RandomHeartsPlugin.java:4: error: package org.bukkit.event does not exist
import org.bukkit.event.EventHandler;
^
plugins\RandomHeartsPlugin.java:5: error: package org.bukkit.event does not exist
import org.bukkit.event.Listener;
^
plugins\RandomHeartsPlugin.java:6: error: package org.bukkit.event.player does not exist
import org.bukkit.event.player.PlayerJoinEvent;
^
plugins\RandomHeartsPlugin.java:7: error: cannot find symbol
import org.bukkit.plugin.java.JavaPlugin;
^
symbol: class JavaPlugin
location: package org.bukkit.plugin.java
plugins\RandomHeartsPlugin.java:11: error: cannot find symbol
public class RandomHeartsPlugin extends JavaPlugin implements Listener {
^
symbol: class JavaPlugin
plugins\RandomHeartsPlugin.java:11: error: cannot find symbol
public class RandomHeartsPlugin extends JavaPlugin implements Listener {
^
symbol: class Listener
plugins\RandomHeartsPlugin.java:19: error: cannot find symbol
public void onPlayerJoin(PlayerJoinEvent event) {
^
symbol: class PlayerJoinEvent
location: class RandomHeartsPlugin
plugins\RandomHeartsPlugin.java:18: error: cannot find symbol
@EventHandler
^
symbol: class EventHandler
location: class RandomHeartsPlugin
plugins\RandomHeartsPlugin.java:13: error: method does not override or implement a method from a supertype
@Override
^
plugins\RandomHeartsPlugin.java:15: error: cannot find symbol
getServer().getPluginManager().registerEvents(this, this);
^
symbol: method getServer()
location: class RandomHeartsPlugin
plugins\RandomHeartsPlugin.java:20: error: cannot find symbol
Player player = event.getPlayer();
^
symbol: class Player
location: class RandomHeartsPlugin
12 errors
Turns out in itelliJ the UI hid it from me