Increase value

Discussion in 'Plugin Development' started by slater96, Aug 8, 2012.

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

    slater96

    I have this
    Code:
    this.playerVotePOTW.put(pExact.getName(), ?);
    Where the question mark is i need to add one each time, i've tried + 1 and Integer.valueOf(1); but neither made it go up by one each time.
     
  2. Offline

    raGan.

    Code:
    this.playerVotePOTW.put(pExact.getName(), this.playerVotePOTW.get(pExact.getName())+1);
     
  3. Offline

    slater96

    I get this error on that line when I do that
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'potw' in plugin PlayerVoter v0.2
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:492)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:878)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:825)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:807)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:281)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:583)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
    at me.slater96.PlayerVoter.PlayerVoter.onCommand(PlayerVoter.java:120)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 15 more
     
  4. Offline

    stelar7

    Does it contain pExact.getName() b4 you do that?
     
  5. Offline

    slater96

    Yeah here's my code
    Code:
    if (args[0].equalsIgnoreCase("Vote")) {
                    if (args.length < 2) {
                        p.sendMessage(ChatColor.RED + "Incorrect Command: You must do /potw vote [playername]");
                        return true;
                    }
                    Player pExact = Bukkit.getPlayerExact(args[1]);
                    if (pExact == null) {
                        p.sendMessage(ChatColor.RED + "That player was not recognised! Is he/she online?");
                        return true;
                    }
                    if (pExact.getName().equals(p.getName())) {
                        p.sendMessage(ChatColor.RED + "You cannot vote for yourself!");
                        return true;
                    }
                    if (this.hasPlayerVoted.containsKey(p.getName())) {
                        p.sendMessage(ChatColor.RED + "You have already voted, wait until next week!");
                        return true;
                    }
                    p.sendMessage(ChatColor.AQUA + "You have sucessfully voted for " + args[1] + "!");
                    this.playerVotePOTW.put(pExact.getName(), this.playerVotePOTW.get(pExact.getName())+1);
                    this.hasPlayerVoted.put(p.getName(), Boolean.valueOf(true));
                    return true;
                }
     
  6. Offline

    stelar7

    afaik, it does not contain it...
     
  7. Offline

    slater96

    How do I make it go up by one each time then?
     
  8. Offline

    Tog

    Not entirely sure what it is you're trying to do, but if you want to be able to count the total votes why not just use a list with names and use the size() method to get the total votes?
     
  9. Offline

    stelar7

    check if this.playerVotePOTW.get(pExact.getName()) == null if it is null, add it, if not, increment it
     
  10. Offline

    slater96

    Oh right, i was just trying to store the players name and vote count and then another command shows how many votes that player has, I'll try using a list thanks.

    I'm still a bit stuck on it, could you give me an example please?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  11. Offline

    stelar7

    Code:
    if(this.playerVotePOTW.get(pExact.getName()) != null) {
        this.playerVotePOTW.put(pExact.getName(), this.playerVotePOTW.get(pExact.getName())+1);
    } else {
        this.playerVotePOTW.put(pExact.getName(), 1);
    }
     
Thread Status:
Not open for further replies.

Share This Page