I found this code which was part of a tutorial. This would be my first plugin but i've found that a lot of things have changed. For example I replaced PLAYER_COMMAND with PLAYER_COMMAND_PREPROCESS. I also added commands to the plugin.yml file. I'm using Eclipsec which says there is a problem with "super(pluginLoader, instance, desc, folder, plugin, cLoader);" and "HashMap". Someone who has built there own plugins would probably see my mistakes easly. Thank you for your help. Error 2011-04-26 01:39:16 [SEVERE] Could not load 'plugins/Basic.jar' in folder 'plugins': java.lang.NoSuchMethodException: com.bukkit.daniel.Basic.Basic.<init>() Basic.java Code: package com.bukkit.daniel.Basic; //All the imports import java.io.File; import java.util.ArrayList; import java.util.HashMap; import org.bukkit.Server; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginManager; /** * Basic for Bukkit * * @author daniel */ //Starts the class public class Basic extends JavaPlugin{ //Links the BasicPlayerListener private final BasicPlayerListener playerListener = new BasicPlayerListener(this); //Links the BasicBlockListener private final BasicBlockListener blockListener = new BasicBlockListener(this); //Create the hashmap "basicUsers" public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap(); //Create the hashmap debugees private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>(); public Basic(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { super(pluginLoader, instance, desc, folder, plugin, cLoader); } @Override //When the plugin is disabled this method is called. public void onDisable() { //Print "Basic Disabled" on the log. System.out.println("Basic Disabled"); } @Override //When the plugin is enabled this method is called. public void onEnable() { //Create the pluginmanage pm. PluginManager pm = getServer().getPluginManager(); //Create PlayerCommand listener //pm.registerEvent(Event.Type.PLAYER_COMMAND, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this); //Create BlockPlaced listener pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this); //Get the infomation from the yml file. PluginDescriptionFile pdfFile = this.getDescription(); //Print that the plugin has been enabled! System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); } //Used when debugging public boolean isDebugging(final Player player) { if (debugees.containsKey(player)) { return debugees.get(player); } else { return false; } } public void setDebugging(final Player player, final boolean value) { debugees.put(player, value); } //The method enabled which checks to see if the player is in the hashmap basicUsers public boolean enabled(Player player) { return this.basicUsers.containsKey(player); } //The method toggleVision which if the player is on the hashmap will remove the player else it will add the player. //Also sends user a message to notify them. public void toggleVision(Player player) { if (enabled(player)) { this.basicUsers.remove(player); player.sendMessage("Basic disabled"); } else { this.basicUsers.put(player, null); player.sendMessage("Basic enabled"); } } } BasicBlockListener.java Code: package com.bukkit.daniel.Basic; //All the imports import com.bukkit.daniel.Basic.BasicPlayerListener; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockListener; //Start the class BasicBlockListener public class BasicBlockListener extends BlockListener{ public static Basic plugin; public BasicBlockListener(Basic instance) { plugin = instance; } //This method is called when ever a block is placed. public void onBlockPlace(BlockPlaceEvent event) { //Get the player doing the placing Player player = event.getPlayer(); //Get the block that was placed Block block = event.getBlockPlaced(); //If the block is a torch and the player has the command enabled. Do this. if(block.getType() == Material.TORCH && BasicPlayerListener.plugin.enabled(player)){ //Tells the player they have placed a torch player.sendMessage("You placed a torch!"); } } } BasicPlayerListener.java Code: package com.bukkit.daniel.Basic; //All the imports import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerListener; //Starts the class BasicPlayer listener public class BasicPlayerListener extends PlayerListener{ public static Basic plugin; public BasicPlayerListener(Basic instance) { plugin = instance; } //This method is called whenever a player uses a command. public void onPlayerCommand(PlayerChatEvent event) { //Make the message a string. String[] split = event.getMessage().split(" "); //Get the player that talked. Player player = event.getPlayer(); //If the first part of the string is /basic or /b then do this. if ((split[0].equalsIgnoreCase("/basic")) || (split[0].equalsIgnoreCase("/b"))) { //Run the method toggleVision for player plugin.toggleVision(player); event.setCancelled(true); } } } plugin.yml Code: name: Basic main: com.bukkit.daniel.Basic.Basic version: 1.0 commands: basic: description: toggles message to tell when a torch is placed or not usage: | /<command> Example: /<command> - Blaa Example: /<command> Blaa g: description: toggles message to tell when a torch is placed or not usage: | /<command> Example: /<command> - Blaa Example: /<command> Blaa
I'm not a plugin dev so I can't help with any actual coding errors but having clicked on the forum before and reading the sticky posts, I do know that the com.bukkit package is now restricted and will cause your plugin to fail. Try changing that first.
@Jeyge For the new bukkit API your package needs to be as follows: me.<yourname>.<yourpluginname> So for you : me.Daniel.Basic Also don't forget to change your plugin main: com.bukkit.daniel.Basic.Basic >> me.Daniel.Basic.Basic
I can see two more errors first delete this: Code: public Basic(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { super(pluginLoader, instance, desc, folder, plugin, cLoader); } You no longer need to use a constructor... And: Code: onPlayerCommand(PlayerChatEvent event) is deprecated now it's: Code: onCommand(CommandSender cs, Command cmnd, String string, String[] strings) Have a look at scrapBukkit, its bukkits sample plugin
One more error: Code: //pm.registerEvent(Event.Type.PLAYER_COMMAND, this.playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this); Delete Player_command_preprocess and just leave player_command with the OnCommand method that I gave you
@Sammy where I give help, you always give better help . No hard feelings though, it's good for the person asking
I read on some other topics that PLAYER_COMMAND is not avaible anymore? Should I just remove this line completely? Code: package me.Daniel.Basic; //All the imports import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerListener; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.ChatColor; //Starts the class BasicPlayer listener public class BasicPlayerListener extends PlayerListener{ public static Basic plugin; public BasicPlayerListener(Basic instance) { plugin = instance; } //This method is called whenever a player uses a command. public void onCommand(CommandSender sender, Command command, String label, String[] args) { //public void onPlayerCommand(PlayerChatEvent event) { //Get the player that talked. Player player = (Player) sender; if (command.getName().equalsIgnoreCase("/basic")){ sender.sendMessage(ChatColor.RED + "You just typed /basic"); //Run the method toggleVision for player plugin.toggleVision(player); } } } The code above I edited for testing purposes it should say "you just type /basic" when player types "/basic". I couldn't get it to do that so i'm assuming thats why "plugin.toggleVision(player);" doesn't work. I'm using "onCommand(CommandSender sender, Command command, String label, String[] args)" rather than "onPlayerCommand(PlayerChatEvent event)" now.
The on command listener looks correct and the code commeneted out you don't need, but the onCommand event needs to go in your main class along with onEnabled and onDisable, it doesn't belong in the playerListener class
A few months ago I had the same "problem", every time I would give help to someone Edward Hand would give a way better solution so I fell you man Yes you are right sorry, i don't use player listener for the commands I extend CommandExecutor... but just do as @Adamki11s use onCommand on the main class and remove the PLAYER_COMMAND Code: if (command.getName().equalsIgnoreCase("/basic")){ dont use the "/", that regex is only needed internally to parse the command, write "basic" only EDIT by Moderator: merged posts, please use the edit button instead of double posting.
With both of your help I was able to get this basic plugin working. Since I now have the basics down I can build on that knowledge. I added the entire source below if anyone else needs the info. If you see any easyer way to do what this plugin does please let me know. Adamki11s and Sammy thanks you again! plugin.yml Code: name: Basic main: me.Daniel.Basic.Basic version: 1.0 commands: basic: description: Tells you when you placed a tourch usage: | /<command> Basic.Java Code: package me.Daniel.Basic; //All the imports import me.Daniel.Basic.commands.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.command.CommandExecutor; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginManager; /** * Basic for Bukkit * * @author daniel */ //Starts the class public class Basic extends JavaPlugin{ //Links the BasicBlockListener private final BasicBlockListener blockListener = new BasicBlockListener(this); //Create the hashmap "basicUsers" public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap(); //public final HashMap<Player, ArrayList<Block>> basicUsers = new HashMap<Player, ArrayList<Block>>(); //Create the hashmap debugees private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>(); @Override //When the plugin is disabled this method is called. public void onDisable() { //Print "Basic Disabled" on the log. System.out.println("Basic Disabled"); } @Override //When the plugin is enabled this method is called. public void onEnable() { //Create the pluginmanage pm. PluginManager pm = getServer().getPluginManager(); //Create PlayerCommand listener //pm.registerEvent(Event.Type.PLAYER_COMMAND, this.playerListener, Event.Priority.Normal, this); getCommand("basic").setExecutor(new Basiccommand(this)); //Create BlockPlaced listener pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this); //Get the infomation from the yml file. PluginDescriptionFile pdfFile = this.getDescription(); //Print that the plugin has been enabled! System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); } //Used when debugging public boolean isDebugging(final Player player) { if (debugees.containsKey(player)) { return debugees.get(player); } else { return false; } } public void setDebugging(final Player player, final boolean value) { debugees.put(player, value); } //The method enabled which checks to see if the player is in the hashmap basicUsers public boolean enabled(Player player) { return this.basicUsers.containsKey(player); } //The method toggleVision which if the player is on the hashmap will remove the player else it will add the player. //Also sends user a message to notify them. public void toggleVision(Player player) { if (enabled(player)) { this.basicUsers.remove(player); player.sendMessage("Basic disabled"); } else { this.basicUsers.put(player, null); player.sendMessage("Basic enabled"); } } } Basiccommand.java Code: package me.Daniel.Basic.commands; //All the imports import me.Daniel.Basic.Basic; import org.bukkit.entity.Player; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.ChatColor; //Starts the class Basiccommand listener public class Basiccommand implements CommandExecutor{ public final Basic plugin; public Basiccommand(Basic plugin) { this.plugin = plugin; } //This method is called whenever a player uses a command. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { //public void onPlayerCommand(PlayerChatEvent event) { Player player = (Player) sender; if (command.getName().equalsIgnoreCase("basic")){ //Run the method toggleVision for player sender.sendMessage(ChatColor.RED + "You just typed /basic"); plugin.toggleVision(player); return true; } else {return false; } } } BasicBlockListener.java Code: package me.Daniel.Basic; //All the imports import me.Daniel.Basic.Basic; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockListener; //Start the class BasicBlockListener public class BasicBlockListener extends BlockListener{ public static Basic plugin; public BasicBlockListener(Basic instance) { plugin = instance; } //This method is called when ever a block is placed. public void onBlockPlace(BlockPlaceEvent event) { //Get the player doing the placing Player player = event.getPlayer(); //Get the block that was placed Block block = event.getBlockPlaced(); //If the block is a torch and the player has the command enabled. Do this. if(block.getType() == Material.TORCH && plugin.enabled(player) ){ //Tells the player they have placed a torch player.sendMessage("test - You placed a torch!"); } } }