Hi, i've been trying to do this plugin for a while now but i can't work out how to do it at all. It's a voting plugin based on Player of the Week (POTW) so I need it to reset each week, computer time not server if you can do that...but the main problem is how to get who has been on in the last week and whether or not if they are offline or online at the time you vote, you still can. Also so you can't vote yourself. Hopefully you understand and please can you try and help as i've asked in the past and not got any response :L Thanks in advance Here's the code i have up to now: Code: public ArrayList<String> Online = new ArrayList<String>(); public HashMap<Player, Integer> Votes = new HashMap<Player, Integer>(); if (args[0].equalsIgnoreCase("Vote")) { if (args.length < 2) { p.sendMessage(ChatColor.RED + "Usage: /POTW vote [playername]"); return true; } if (this.getServer().getPlayer(args[1]).isOnline()) { this.Votes.put(p, + 1); p.sendMessage("Voted"); } else { p.sendMessage("Player is not online"); } if (this.getServer().getPlayer(args[1]).getName() == p.getName()) { p.sendMessage("You cannot vote for yourself!"); } } if(args[0].equalsIgnoreCase("List")) { Player target = p.getServer().getPlayer(args[1]); if (this.Votes.containsKey(target)) { p.sendMessage(this.Votes.get(args[1]).toString()); } } @EventHandler public void onJoin(PlayerJoinEvent event) { Player p = event.getPlayer(); String pname = p.getName(); if (!plugin.Online.contains(pname)) { plugin.Online.add(pname); p.sendMessage("Added to Online!"); } } }
Where does the player vote? As far as I can see, there is nowhere the player votes. It looks like you are sending a message to the players that /POTW is a vote command or something, but I see no command method. In addition, for weekly resets I think you need to use the Bukkit Scheduler, and there is documentation for it at http://wiki.bukkit.org/Scheduler_Programming. I'm a noob but maybe I'm on the right track here...
Yeah the main command is /potw but it just shows help for the /potw list and vote [playername] so i didn't post it. I thought the bukkit scheduler used server time, not computer time...anyone help me on this please?
Well once again im just guessing, but Java has a class called Calendar which deals with dates and time, so you can easily use and manipulate time. I'm not sure how well you can integrate that on your server, but its worth looking into in my opinion.
Use an arraylist.... add to it when the player votes then get the value of the arraylist to see how many people voted for that thing
I thought an ArrayList doesn't allow duplicates so there's no way to count the votes, if there is can you show me some example code please as I don't quite understand.
You have some logic issues there... you're checking if you can't vote yourself AFTER you already process the vote ? Move that section of code before and add a "return;" to it as well. Also, doesn't your IDE warn you about: this.Votes.put(p, + 1); ? Since " + 1" isn't a corect syntax... you'll have to get player's votes first. And don't use Player for storage, use String and player's name instead.
Ok thanks, i've changed it now, what do I add instead of + 1 Code: if (args[0].equalsIgnoreCase("Vote")) { if (args.length < 2) { p.sendMessage(ChatColor.RED + "Usage: /POTW vote [playername]"); return true; } if (this.getServer().getPlayer(args[1]).getName() == p.getName()) { p.sendMessage("You cannot vote for yourself!"); return false; } else { if (this.getServer().getPlayer(args[1]).isOnline()) { this.Votes.put(p.getName(), 1); p.sendMessage("Voted"); } } }
Do you want each time a player types /vote to ADD a vote ? That can lead to exploits... I am unsure what you really want. If you just want to register a single vote from each player, use a List.
I want it so people can do /potw vote [playername] in a week, so yes thats a single vote in a week. Never used a List before...
It's just like an ArrayList. But for speed, a HashSet would be faster for .contains() I belive, and it has similar methods to List. So, just use one of those with String as type and store players' names, check if player's name is not in the list with .contains() and then add him to the list... then after a week just clear the list/set.
You could've googled instead of waiting for reply :} Code: private List<String> playerVotes = new ArrayList<String>(); private if you're only going to use it in that class or protected if you're going to use it in other classes in the same package (folder).
Sorry i'm confused, i tried doing what you said but it said to remove arguments, so i changed new ArrayList to new List but it still shows errors saying it should be like this private List playerVotes = new List();
It must work as List<String> to be able to define what type to store... there's something wrong with your IDE or something if it says it's wrong.