Skip to content

Commit

Permalink
Display vote options when the player types "/vote"
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWoodworth committed May 14, 2016
1 parent 7daaf73 commit b9d9813
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/ritcraft/RockTheVote/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
* Configuration for this plugin's messages.
Expand Down Expand Up @@ -107,4 +108,13 @@ public static String getVoteNotFound(String vote) {
public static String getVotePlayerOnly() {
return get("vote-player-only");
}

public static String getVoteList(List<String> votes) {
String[] names = new String[votes.size()];
for (int i = 0; i < names.length; i++) {
names[i] = get("vote-list.vote", "vote", votes.get(i));
}
String separator = get("vote-list.separator");
return get("vote-list.format", "votes", String.join(separator, names));
}
}
17 changes: 15 additions & 2 deletions src/main/java/net/ritcraft/RockTheVote/commands/CmdVote.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -38,8 +40,19 @@ public List<String> onTabComplete(CommandSender sender, String[] args) {
}

public void showVotes(Player player, String startingWith) {
player.sendMessage("You're out of luck... this feature hasn't been implemented yet. :(");
player.sendMessage("Normally you would see what votes are available when you run this command.");
List<String> matches = new ArrayList<>();
startingWith = startingWith.toLowerCase();
for (String name : RockTheVote.getVoteManager().getVoteNames()) {
if (name.toLowerCase().startsWith(startingWith)) {
matches.add(name);
}
}

// Sort matches alphabetically
Collections.sort(matches, String::compareToIgnoreCase);

// Show vote list to player
player.sendMessage(Language.getVoteList(matches));
}

public void castVote(Player player, String voteName) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/ritcraft/RockTheVote/vote/VoteManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.bukkit.configuration.ConfigurationSection;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Manage all of the votes.
Expand Down Expand Up @@ -104,13 +106,26 @@ public Vote getVote(String voteName) {
return votes.get(voteName.toLowerCase());
}

/**
* Get all vote names.
*
* @return Returns the vote names.
*/
public Set<String> getVoteNames() {
Set<String> result = new HashSet<>();
for (Vote vote : votes.values()) {
result.add(vote.getName());
}
return result;
}

/**
* Disable all of the loaded votes
*/
public void disableVotes() {
for (String s : votes.keySet()) {
votes.get(s).disable();
votes.remove(s);
}
votes.clear();
}
}
11 changes: 8 additions & 3 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
vote-bar-title: '&6&l<desc> &7-&6&l Votes: <count>/<total> &7-&6&l /vote <vote>' # Variables: vote, desc, count, total
vote-bar-title: '&6&l<desc> &7-&6&l /vote <vote> &7-&6&l Votes: <count>/<total>' # Variables: vote, desc, count, total

invalid-bar-color: '&cInvalid value for bar-color: <value>' # Variables: value
invalid-bar-style: '&cInvalid value for bar-style: <value>' # Variables: value

vote-cast: '&aYour vote for &b<vote>&a has been cast' # Varibles: vote
vote-not-found: '&cThere is no vote with the name &b<vote>' # Variables: vote
vote-cast: '&bYour vote for &a<vote>&b has been cast' # Varibles: vote
vote-not-found: '&cThere is no vote with the name &4<vote>' # Variables: vote
vote-player-only: '&cYou must be a player to cast a vote'
vote-list:
format: '&bVotes: <votes>'
vote: '&a<vote>'
separator: '&b, '

0 comments on commit b9d9813

Please sign in to comment.