Plugin casting Boolean to String even though I don't think it's in the code

Discussion in 'Plugin Development' started by Wolf7115, Dec 14, 2011.

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

    Wolf7115

    I get this when I try to start my server:
    Code:
    [SEVERE] java.lang.Boolean cannot be cast to java.lang.String loading WolFactions v0.1 (Is it up to date?)
    java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    I've searched for a very long time and I have even undone every single thing I've done to my code to before this happened and when it actually worked. I'm assuming this may be an issue with something else on the server somewhere? Is this an issue that anybody else has gotten before?
     
  2. Offline

    Chiller

    You are trying to set a boolean to a String
     
  3. No, this is a problem in your plugin. You are doing something like String playerName = config.getBoolean("bla").

    My point is that you are trying to make an illegal cast. If you can't seem to figure out the problem on your own now, post your code.
     
  4. Paste the code ;) You are trying to cast a boolean to a string.
     
  5. Offline

    Wolf7115

    Sorry it took me a while to paste the code, if any of you can find my problem with this, I love you.
    Also, I know this code is a bit messy, I just need to clean it up later... as soon as it actually starts working again.
    Code:
    package me.wolf7115.wolfactions;
    
    import java.io.File;
    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.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class WolFactions extends JavaPlugin{
        Logger logger = Logger.getLogger("Minecraft");
        public File pFolder = new File("plugins/WolfMMO");
        private WolFactionsPlayerListener playerListener = new WolFactionsPlayerListener(this);
        private Stats stats = new Stats(this);
    
        public ArrayList<String> magmite = new ArrayList<String>();
        public ArrayList<String> auga = new ArrayList<String>();
        public ArrayList<String> treehuggers = new ArrayList<String>();
        public ArrayList<String> aero = new ArrayList<String>();
    
        public ArrayList<String> factionChat = new ArrayList<String>();
        public ArrayList<String> resetPurchased = new ArrayList<String>();
    
        public void onEnable(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
            logMessage("Enabled.");
    
            //Remove after faction switching works.
            auga.add("White_Glint");
            magmite.add("Wolf7115");
            treehuggers.add("VidarVali");
            treehuggers.add("thebearjew09");
            treehuggers.add("_Enir_boreh_");
            aero.add("Epic_Box");
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("f")){
                if(sender instanceof Player == false){
                    this.logMessage("This command can only be used in game.");
                }
    
                Player p = (Player) sender;
                String pname = p.getName();
    
                if(magmite.contains(pname) || auga.contains(pname) || treehuggers.contains(pname) || aero.contains(pname)){
                    if(factionChat.contains(pname)){
                        factionChat.remove(pname);
                        p.sendMessage(ChatColor.DARK_GREEN + "Leaving (FACTION) Chat.");
                    }else{
                        factionChat.add(pname);
                        p.sendMessage(ChatColor.DARK_GREEN + "Entering (FACTION) Chat.");
                    }
                }else{
                    p.sendMessage(ChatColor.DARK_RED + "Nomads do not have access to (FACTION) Chat.");
                }
            }else if(cmd.getName().equalsIgnoreCase("reset")){
                if(sender instanceof Player == false){
                    String playerToReset = args[0];
                    resetPurchased.add(playerToReset);
                    resetPlayerNotification(playerToReset);
                }else{
                    Player p = (Player) sender;
                    if(resetPurchased.contains(p.getName())){
                        resetCharacter(p);
                    }else{
                        sender.sendMessage(ChatColor.DARK_RED + "Thalt shalt not smite thine enemies.");
                    }
                }
            }else if(cmd.getName().equalsIgnoreCase("no")){
                if(sender instanceof Player){
                    String pname = sender.getName();
                    if(resetPurchased.contains(pname)){
                        resetPurchased.remove(pname);
                        sender.sendMessage(ChatColor.DARK_GREEN + "Character reset cancelled.");
                    }
                }
            }
            return true;
        }
    
        public void onDisable(){
            //Save Faction information.
            logMessage("Factions saved.");
            logMessage("Disabled.");
        }
    
        public void logMessage(String msg){
            PluginDescriptionFile pdfFile = getDescription();
            logger.info(pdfFile.getName() + " v" + pdfFile.getVersion() + ": " + msg);
        }
    
        public void resetPlayerNotification(String pname){
            for(Player onlinePlayer : getServer().getOnlinePlayers()){
                String playername = onlinePlayer.getName();
                if(playername == pname){
                    onlinePlayer.sendMessage(ChatColor.DARK_RED + "YOU HAVE A PENDING CHARACTER RESET ON THIS ACCOUNT.");
                    onlinePlayer.sendMessage(ChatColor.DARK_RED + "Use /reset to reset your character.");
                    onlinePlayer.sendMessage(ChatColor.DARK_RED + "Use /no to not reset and never get this message again.");
                    onlinePlayer.sendMessage(ChatColor.DARK_RED + "THIS CANNOT BE UNDONE!");
                }
            }
        }
    
        public void resetCharacter(Player p){
            resetPurchased.remove(p);
            stats.startNewChar(p);
        }
    }
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    @Wolf7115
    you should also post the rest of that error. where it starts with all the line numbers and file names.
     
  7. Offline

    Wolf7115

    @Sagacious_Zed
    This is all that the console is giving me:
    [​IMG]
    I can normally find my issues with my code, but this one is way above my head.
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    @Wolf7115
    O.O
    well that was unexpected. I'm intrigued.
     
    wwsean08 likes this.
  9. Offline

    wwsean08

    agreed, and i'm not seeing anything in your code, mind posting your plugin.yml i have 1 possible idea
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    now that @wwsean08 mentioned it @Wolf7115 do you by chance have a string that reads true or false in any of your yaml files?
     
  11. Offline

    wwsean08

    yah i was kinda thinking something along the same lines for the plugin.yml (just because it would seem it doesn't get far enough to get to the other yaml's)
     
  12. Offline

    Wolf7115

    @Sacious_Zed @wwsean08
    This is my yaml:
    Code:
    name: WolFactions
    version: 0.1
    main: me.wolf7115.wolfactions.WolFactions
    commands:
        f:
            description: Toggles between Faction and global chat.
            usage: /f
        reset:
            description: Resets the desired User.
            Usage: /reset [name]
        no:
            description: Say no to resets!
            Usage: /no
    permissions:
        factions.vip:
            description: Adds VIP tag in front of name.
            default: op
        factions.admin:
            description: Allows admins to set spawn points.
            default: op
     
  13. Offline

    coldandtired

    Pretty sure you can't have a key called 'no' in YAML.
     
  14. Offline

    Wolf7115

    @coldandtired I'm going to change that. If it does work I will just facepalm myself.

    EDIT: It worked. I feel like such a derp now. Thanks everyone for helping me.
     
  15. Offline

    coldandtired

    You might be able to make it work by making it "no" (with the quotes) as this should force it to a string, but in YAML yes and no are used the same as true and false.
     
  16. Offline

    Wolf7115

    I did not know that. Thanks for the information.
     
Thread Status:
Not open for further replies.

Share This Page