Stuck with errors (lots of errors)

Discussion in 'Plugin Development' started by Hello Minecraft World, Jan 9, 2012.

Thread Status:
Not open for further replies.
  1. Ok i made a plugin but only one of my commands seem to work, my motd cmd so what is wrong with this code?
    TobiMotd.java
    Code:java
    1. package com.rosaage.Tobi;
    2.  
    3. import org.bukkit.configuration.file.FileConfiguration;
    4. import org.bukkit.event.Event;
    5. import org.bukkit.event.player.PlayerJoinEvent;
    6. import org.bukkit.plugin.PluginManager;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. import org.bukkit.event.Event.*;
    9. import org.bukkit.command.*;
    10. import org.bukkit.event.player.PlayerListener;
    11. public class TobiMotd extends JavaPlugin {
    12.  
    13. private final TobiMotdPlayerListener playerListener = new TobiMotdPlayerListener(this);
    14.  
    15. public TobiMotd plugin;
    16.  
    17. public void onDisable() {
    18. System.out.println("[TobiMotd] v1.3 is disabled!");
    19. }
    20. public void onEnable() {
    21. PluginManager pm = this.getServer().getPluginManager();
    22. final FileConfiguration config = this.getConfig();
    23. config.addDefault("MOTD", "&4This is my &emotd");
    24. config.addDefault("Use.Permissions", true);
    25. config.addDefault("Reload.Command", "tm");
    26. pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
    27.  
    28. getCommand("motd").setExecutor(new CommandExecutor(){
    29. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    30. if(cmd.getName().equalsIgnoreCase("motd")){
    31. sender.sendMessage(config.getString("MOTD").replaceAll("(&([a-f0-9]))", "\u00A7$2"));
    32. return true;
    33. }
    34. return false;
    35. }
    36. });
    37. getCommand("setmotd").setExecutor(new CommandExecutor(){
    38. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    39. if(cmd.getName().equalsIgnoreCase("setmotd")){
    40. int value = (Integer.parseInt(args[0]));
    41. config.set("MOTD", value);
    42. saveConfig();
    43. reloadConfig();
    44. return true;
    45. }
    46. return false;
    47. }
    48. });
    49. this.getServer().getPluginManager().registerEvent(Type.PLAYER_JOIN, new PlayerListener() {
    50. @Override
    51. public void onPlayerJoin(PlayerJoinEvent event) {
    52. event.getPlayer().sendMessage(config.getString("MOTD").replaceAll("(&([a-f0-9]))", "\u00A7$2"));
    53. }
    54. }, Priority.Normal, this);
    55. this.getConfig().options().copyDefaults(true);
    56. saveConfig();
    57. System.out.println("[TobiMotd] v1.3 is enabled!");
    58. }
    59. }
    60.  

    TobiMotdPlayerListener.java
    Code:java
    1. package com.rosaage.Tobi;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    6. import org.bukkit.event.player.PlayerListener;
    7.  
    8. public class TobiMotdPlayerListener extends PlayerListener{
    9.  
    10. public TobiMotd plugin;
    11. public TobiMotdPlayerListener(TobiMotd instance) {
    12. plugin = instance;
    13. }
    14.  
    15. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    16. String[] s = event.getMessage().split(" ");
    17. Player player = event.getPlayer();
    18. if (s[0].equalsIgnoreCase(plugin.getConfig().getString("Reload.Command"))) {
    19. if (plugin.getConfig().getBoolean("Use.Permissions")) {
    20. if(player.hasPermission("tobimodt.reload") || player.isOp()){
    21. plugin.reloadConfig();
    22. plugin.saveConfig();
    23. player.sendMessage(ChatColor.DARK_AQUA + "Config reloaded!");
    24. }
    25. else{
    26. player.sendMessage(ChatColor.RED + "You Do Not Have Access to That Command!");
    27. }
    28. }
    29. else{
    30. if(player.isOp()) {
    31. plugin.reloadConfig();
    32. plugin.saveConfig();
    33. player.sendMessage(ChatColor.DARK_AQUA + "Config reloaded!");
    34. }
    35. else{
    36. player.sendMessage(ChatColor.RED + "You Do Not Have Access to That Command!");
    37. }
    38. }
    39. }
    40. player.sendMessage(ChatColor.RED + "ERROR!");
    41. }
    42. }
    43.  
     
  2. If you want to test here is the .jar file
     

    Attached Files:

  3. What errors are you getting ?
     
  4. Can't Get Them before tomorrow
    But you can try the Jar file and the commands
    The Jar file is in a earlier post i made
     
Thread Status:
Not open for further replies.

Share This Page