Solved Code help

Discussion in 'Plugin Help/Development/Requests' started by Sarcry, Aug 26, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Sarcry

    I've recived an error when enabling the plugin. Here's the code:
    Code:
    public class Punish extends JavaPlugin {
        public final Logger  logger = Logger.getLogger("Minecraft");
     
        public void onEnable() {
            getLogger().info(ChatColor.BOLD.toString() + ChatColor.GREEN + "[BAN] has been enabled!");
            getServer().getPluginManager();
        }
        public void onDisable() {
            getLogger().info(ChatColor.BOLD.toString() + ChatColor.RED + "[BAN] has been disabled!");
        }
        @SuppressWarnings("deprecation")
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("ban")) {
                if (p.hasPermission("ban.ban")) {
                    if (args.length == 0) {
                        p.sendMessage(ChatColor.DARK_RED + "WARNING: You must specify a player." );
                    }
                    if(Bukkit.getPlayer(args[0]).isOnline()) {
                        Player tpplayer = getServer().getPlayer(args[0]);
                        tpplayer.setBanned(true);
                        tpplayer.kickPlayer(ChatColor.BOLD.toString() + ChatColor.DARK_RED + "You were banned from the server by " + ChatColor.GOLD + p.getName() + "!");
                        Bukkit.broadcastMessage(ChatColor.BOLD.toString() + ChatColor.YELLOW + "The player " + ChatColor.GOLD + tpplayer.getName() + ChatColor.YELLOW + " was banned from the server by " + ChatColor.DARK_PURPLE + sender.getName()  );
                    } else {
                        OfflinePlayer oplayer = getServer().getOfflinePlayer(args[0]);
                        oplayer.setBanned(true);
                        Bukkit.broadcastMessage(ChatColor.BOLD.toString() + ChatColor.YELLOW + "The player " + ChatColor.GOLD + oplayer.getName() + ChatColor.YELLOW + " was banned from the server by " + ChatColor.DARK_PURPLE + sender.getName() );
                     
                }
                    if (args.length == 2 ) {
                        Player tpplayer = getServer().getPlayer(args[0]);
                        if(Bukkit.getPlayer(args[0]).isOnline()){
                     
                        tpplayer.setBanned(true);
                        tpplayer.kickPlayer(ChatColor.BOLD.toString() + ChatColor.DARK_RED + "You were banned from the server by " + ChatColor.GOLD + p.getName() + "for" + args[+1]);
                        Bukkit.broadcastMessage(ChatColor.BOLD.toString() + ChatColor.YELLOW + "The player " + ChatColor.GOLD + tpplayer.getName() + ChatColor.YELLOW + " was banned from the server by " + ChatColor.DARK_PURPLE + sender.getName() + " for " + ChatColor.YELLOW + args[+1] );
                   
                    } else {
                        OfflinePlayer oplayer = getServer().getOfflinePlayer(args[0]);
                       
                           oplayer.setBanned(true);
                           Bukkit.broadcastMessage(ChatColor.BOLD.toString() + ChatColor.YELLOW + "The player " + ChatColor.GOLD + tpplayer.getName() + ChatColor.YELLOW + " was banned from the server by " + ChatColor.DARK_PURPLE + sender.getName() + " for " + ChatColor.YELLOW + args[+1] );
                    }
                     
            }
                }
             
         
        }
            return false;
     
        }
     
    }
    
    And here's the plugin.yml:
    Code:
    name: Ban
    main: sar.ban.Punish
    version: 1.0
    commands:
         description: Bans players.
         usage: /ban <player> <reaso
    
    Here's the error:
    Code:
    [19:26:13] [Server thread/ERROR]: Could not load 'plugins\Ban.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: commands are of wrong type
        at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:946) ~[craftbukkit.jar:git-Bukkit-5e5cf84]
        at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:232) ~[craftbukkit.jar:git-Bukkit-5e5cf84]
        at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:157) ~[craftbukkit.jar:git-Bukkit-5e5cf84]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:294) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at org.bukkit.craftbukkit.v1_10_R1.CraftServer.<init>(CraftServer.java:256) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at net.minecraft.server.v1_10_R1.PlayerList.<init>(PlayerList.java:70) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at net.minecraft.server.v1_10_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at net.minecraft.server.v1_10_R1.DedicatedServer.init(DedicatedServer.java:184) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:514) [craftbukkit.jar:git-Bukkit-5e5cf84]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
        at org.bukkit.plugin.PluginDescriptionFile.loadMap(PluginDescriptionFile.java:928) ~[craftbukkit.jar:git-Bukkit-5e5cf84]
        ... 10 more
    
    Issued solved.
     
    Last edited: Aug 26, 2016
  2. Offline

    bwfcwalshy Retired Staff

    @Sarcry That onEnable and onDisable is just useless, don't log onEnable and onDisable. Remove onDisable, not needed. Check before casting, even if it is 0 args the command will try and get the player and will error, getPlayer() and isOnline will still throw an error, setBanned is deprecated, your plugin.yml doesn't have the command.
     
Thread Status:
Not open for further replies.

Share This Page