Error at Minecraft Plugin - java

I've an error when I'm launching my minecraft server. The external library I'm using for the plugin is the recommended build craftbukkit-1.6.4-R2.0. I'm using the craftbukkit-1.6.4-R2.0 to launch the server and as the external library in eclipse(java).
This is some of the error that I'm receiving:
Could not load 'plugins\Test.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: me.Bench3.youtube.Youtube
at org.bukkit.plugin.java.javaPluginloader.LoadPlugin(JavaPluginLoader.java:184)
and it continues.
Does anyone around here know how to fix this problem?
My code to the plugin is:
package me.Bench3.youtube;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
public class Youtube extends JavaPlugin{
public final Logger logger = Logger.getLogger("Minecraft");
public static Youtube plugin;
#Override
public void onDisable(){
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(pdfFile.getName() + " Has been disabled!");
}
#Override
public void onEnable(){
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has been enabled!"); //You
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
Player player = (Player) sender;
if (commandLabel.equalsIgnoreCase("sendme"))
{
player.sendMessage(ChatColor.BLUE + "Sent");
}
return false;
}
}
This is my plugin.yml
main: me.Bench3.yotube.Youtube
name: Youtube
version: 1.0

Its in the plugin.yml change it to me.Bench3.youtube.Youtub from me.Bench3.yotube.Youtub(you forgot a u)

The error your describe indicates your class me.Bench3.youtube.Youtube is not on the classpath. Make sure your jar/classes are on the classpath prior to executing the java application.

I know this is a bit late, but you have to use bukkit.jar as your referenced library, not the server jar. Head over to http://dl.bukkit.org/downloads/bukkit/ to get the latest n greatest build for your referenced library.

Related

Is there an implemented function in Bukkit / Spigot MC (Java) that lets me get a players ping to the server? [duplicate]

This question already has an answer here:
How to get player's ping in spigot 1.16.4
(1 answer)
Closed 2 years ago.
I'm currently trying to code a Minecraft plugin for a server that a Streamer friend of mine wants to run. What I need is the following:
I need a function or method that lets me get the players ping towards the server. So that the player types /ping into the chatbox and gets a response from the server that looks something like [Server]: Your current Ping is 62ms.
I've looked in Bukkit documentation like http://docs.codelanx.com/Bukkit/1.7.10/ or http://bukkit.luricos.de/api/1.7.9-R0.2/, but I couldn't find something that fits my needs.
My Plugin.yml:
name: Beginning
version: ${project.version}
main: de.nightcore.beginning.Main
api-version: 1.16
commands:
date:
description: Shows the current time and Date
ping:
description: Gives the Player its current ping to the server
My Main Class:
package de.nightcore.beginning;
import de.nightcore.beginning.commands.DateCommand;
import de.nightcore.beginning.commands.PingCommand;
import de.nightcore.beginning.listeners.JoinListener;
import de.nightcore.beginning.listeners.QuitListener;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin {
#Override
public void onEnable()
{
Bukkit.getLogger().fine("Plugin wird geladen!");
listenerRegistration();
commandRegistration();
}
#Override
public void onDisable()
{
Bukkit.getLogger().fine("Plugin wird beendet!");
}
public static String getPrefix()
{
return ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Server" + ChatColor.DARK_GRAY + "] " + ChatColor.WHITE;
}
private void listenerRegistration()
{
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new JoinListener(), this);
pluginManager.registerEvents(new QuitListener(), this);
}
private void commandRegistration()
{
getCommand("date").setExecutor(new DateCommand());
getCommand("ping").setExecutor(new PingCommand());
}
}
And finally my PingCommand Class:
package de.nightcore.beginning.commands;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
//TODO: Ping Command / Command that provides Connection Info
public class PingCommand implements CommandExecutor {
#Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player player = sender.getServer().getPlayer("%UUID%"); ;
Server server = sender.getServer();
//Source Code to provide information about the players current ping
return false;
}
}
You need to cast Player to CraftPlayer, after that get the EntityPlayer with CraftPlayer#getHandler(), where you can return the player ping as int value.
((CraftPlayer) player).getHandle().ping;
You also need to add the spigot dependency (the API doesn't seem to include it).
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>

Minecraft Spigot Command Not Enabling in Main Class

My Command (Specifically only my cmd2 command) doesn't register, and the console displays an error when I start the server. The other command, cmd1, works, but cmd2 doesn't. I'm really not sure why, so I came here for help.
Some of my Main Class:
package me.Vamp.Test;
import me.Vamp.Test.Events.EventsClass;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
private Commands commands = new Commands();
#Override
public void onEnable() {
/* Enabler */
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "\n\nTest Plugin has been enabled.\n\n");
/* Events Register */
getServer().getPluginManager().registerEvents(new EventsClass(), this);
/* Commands Register */
getCommand(commands.cmd1).setExecutor(commands);
getCommand(commands.cmd2).setExecutor(commands);
}
}
The following Class (Commands) only show for the errored command (cmd2). If the code for cmd1 is needed, I will show it.
Some of My Command Class:
package me.Vamp.Test;
import org.bukkit.Material;
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;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
public class Commands implements Listener, CommandExecutor {
public String cmd2 = "getpickaxe";
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
/*
/getPickaxe Command
*/
if (cmd.getName().equalsIgnoreCase(cmd2)) {
Player player = (Player) sender;
if (args.length == 0) {
commandGetPickaxe(player);
return true;
} else {
player.sendMessage(Colors.chat("&c&lERROR &cToo many arguments&8."));
return true;
}
}
} else {
sender.sendMessage(Colors.chat("&c&lERROR &cOnly players can use this command&8."));
return true;
}
return false;
}
public void commandGetPickaxe(Player player){
Inventory inv = player.getInventory();
ItemStack item = new ItemStack(Material.WOOD_PICKAXE, 1);
ItemMeta meta = item.getItemMeta();
ArrayList<String> lore = new ArrayList<String>();
meta.setDisplayName(Colors.chat("&3Wooden Pickaxe"));
lore.add(Colors.chat("&7&oThe Starter Pickaxe&8&o."));
meta.setLore(lore);
item.setItemMeta(meta);
inv.addItem(new ItemStack(item));
player.sendMessage(Colors.chat("&8&l» &3You have received a Wooden Pickaxe&8."));
}
}
This is only the display error on my console.
My Console:
Console
Can I suggest you add a multitude of print statements to see what is null?
/* Commands Register */
System.out.println("cmd1 " + commands.cmd1);
System.out.println("cmd2 " + commands.cmd2);
System.out.println("cmdObj " + commands);
getCommand(commands.cmd1).setExecutor(commands);
getCommand(commands.cmd2).setExecutor(commands);
EDIT 1: It seems as though you are missing the command in your plugin.yml?
It's possible that it is a typo, look carefully. If you think everything is perfectly fine, and the error still occurs, please edit you original post and include the plugin.yml file. Thanks!

Bukkit plugin not loaded (only one command)

I'm new in java and bukkit api and server can't load my plugin, error in console: https://pastebin.com/GzgLhHp6. Maybe problem in "private Plugin plugin" whick is not used, eclipse warned. My code:
Plugin.java
package Iaiao.main;
import org.bukkit.plugin.java.JavaPlugin;
public class Plugin extends JavaPlugin {
public void onEnable () {
getCommand("ip").setExecutor(new Commands(this));
getLogger().info("Enabled!");
}
}
Commands.java
package Iaiao.main;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commands implements CommandExecutor {
private Plugin plugin;
public Commands(Plugin plugin) {
this.plugin = plugin;
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(args.length == 0) {
return false;
}
String name = args[0];
Player p = Bukkit.getPlayer(name);
if(p == null) {
sender.sendMessage("This player is offline or not registered");
return true;
}
sender.sendMessage("Ip: " + p.getAddress().getAddress());
return true;
}
}
plugin.yml
name: Plugin
main: Iaiao.main.Plugin
version: 1.0
commands:
ip:
description: Player's IP
usage: /ip <player>
Your plugin.yml is not valid:
org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
Somewhere in you plugin.yml is a tab character which must not be used.
Just read the whole error message. It gives you hints where errors occured.

streamscraper java lib eclipse

I have this code:
import java.net.URI;
import java.util.List;
import net.moraleboost.streamscraper.Stream;
import net.moraleboost.streamscraper.Scraper;
import net.moraleboost.streamscraper.scraper.IceCastScraper;
public class Harvester
{
public static void main(String[] args) throws Exception
{
Scraper scraper = new IceCastScraper();
List<Stream> streams = scraper.scrape(new URI("http://host:port/"));
for (Stream stream: streams) {
System.out.println("Song Title: " + stream.getCurrentSong());
System.out.println("URI: " + stream.getUri());
}
}
}
Where do I download JAR for import net.moraleboost.streamscraper.* to work? I can find source code for it but I gives me load of errors, can someone just provide me .jar so I could include in java build path library?
You can clone the repository at https://code.google.com/p/streamscraper/
You can also download the code from here: https://code.google.com/p/streamscraper/source/browse/

Bukkit won't load the plugin: name is not defined

Here's my code:
package me.chimericalhobo.BlockChanger;
import java.util.ArrayList;
import java.util.logging.Logger;
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 BlockChanger extends JavaPlugin
{
private static final Logger log = Logger.getLogger("Minecraft");
private final BlockChangerListener blockListener = new BlockChangerListener(this);
public final ArrayList<Player> BlockChangerUsers = new ArrayList<Player>();
#Override
public void onEnable()
{
log.info("[BlockChanger] has been enabled!");
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(this.blockListener, this);
}
#Override
public void onDisable()
{
log.info("[BlockChanger] has been disabled!");
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
if(commandLabel.equalsIgnoreCase("BlockChanger"))
toggleBlockChanger(sender);
return true;
}
private void toggleBlockChanger(CommandSender sender)
{
if(!enabled((Player) sender)){
BlockChangerUsers.add((Player) sender);
((Player) sender).sendMessage(ChatColor.BLUE + "BlockChanger has been enabled!");
}
else
{
BlockChangerUsers.remove((Player) sender);
((Player) sender).sendMessage(ChatColor.RED + "BlockChanger has been disabled!");
}
}
public boolean enabled(Player player)
{
return BlockChangerUsers.contains(player);
}
}
Every time I try to load it the command prompt says:
15:53:08 [SEVERE] Could not load 'plugins\BlockChanger.jar' in folder 'plugins'
org.bukkit.plugin.InvalidDescriptionException: name is not defined
In the plugin.yml add this:
name: (Plugin Name)
main: (Package.name.name(or whatever).(MainClass Ex: .Main)) Ex: me.name.plugin.Main
version: (Version number)
Optionally you can add things such as author: (author name).
Look at http://wiki.bukkit.org/Plugin_YAML for more information.
A plugin needs to consist of a name.
In the plugin.yml you will see a field that says:
name:
Here you must insert a name of your plugin.
A complete example of a plugin.yml looks like this:
name: Velocity Jump
main: com.weebly.foxgenesis.Main
version: 1.0
commands:
vjump:
description: make a player velocity jump to you
usage: /vjump <player> [toPlayer] [time]
default: op
For more info please click this link: http://wiki.bukkit.org/Plugin_YAML
Check your plugin.yml.
Are you sure you have set a name: <plugin name> field in it?

Categories