Conversation
Electroid
left a comment
There was a problem hiding this comment.
Awesome job! It will be nice to have refactored polls so more features can implement them. Mostly minor fixes and changes.
|
|
||
| public Poll(PollManager pollManager, Server server, String initiator) { | ||
| protected final PollManager pollManager; | ||
| protected final String initiator; |
There was a problem hiding this comment.
I would suggest changing the initiator to be a PlayerId so that you can fix the bug where nicked players are exposed if they create a poll.
There was a problem hiding this comment.
that feels like it would be a bit restrictive, if other systems want to use polls (say the veto system for tournaments) forcing it into a player id may not be that good
There was a problem hiding this comment.
Tournaments are an entirely different system. Besides, if you were to refactor this for teams, it would just make more complicated. It's a reasonable assumption that a poll is initiated by a person and not something else.
| } | ||
| if (sender instanceof Player) { | ||
| Player player = (Player) sender; | ||
| if (TokenUtil.getUser(player).maptokens() < 1) { |
There was a problem hiding this comment.
I would add a util method for TokenUtil.getUser(CommandSender)
| throw new TranslatableCommandException("poll.map.notallowed"); | ||
| } | ||
|
|
||
| if (PGM.get().getServer().getOnlinePlayers().size() * 4 / 5 > nextMap.getDocument().max_players() && !sender.hasPermission("poll.next.override")) { |
There was a problem hiding this comment.
Instead of PGM.get()... inject OnlinePlayers and use its methods.
| throw new TranslatableCommandException("poll.map.notallowed"); | ||
| } | ||
|
|
||
| if (PGM.get().getServer().getOnlinePlayers().size() * 4 / 5 > nextMap.getDocument().max_players() && !sender.hasPermission("poll.next.override")) { |
There was a problem hiding this comment.
It accounts for some observers being afk.
|
|
||
| if (args.getSuggestionContext() != null) { | ||
| Collection<Mutation> availableMutations = Sets.newHashSet(Mutation.values()); | ||
| availableMutations.removeAll(mutationQueue.mutations()); |
There was a problem hiding this comment.
I would add a convenience method for mutationsAvailable
| Mutation mutation = StringUtils.bestFuzzyMatch(mutationString, Sets.newHashSet(Mutation.values()), 0.9); | ||
| if(mutation == null) { | ||
| throw new TranslatableCommandException("command.mutation.error.find", mutationString); | ||
| } else if(MutationCommands.getInstance().getMutationQueue().mutations().contains(mutation)) { |
There was a problem hiding this comment.
Avoid statically referencing other injected commands like MutationsCommands. All you need is the MutationQueue object, which you already have as a local variable in mutationQueue
| PollCustom create(String text, CommandSender initiator); | ||
| } | ||
|
|
||
| private String text; |
There was a problem hiding this comment.
Instead of passing a text object, can that just be a method?
getReasonString() or getPollString()
There was a problem hiding this comment.
Where would you put the method? PollCustom needs it to be able to display the message they player used.
|
|
||
| @Override | ||
| public void executeAction() { | ||
| if(player != null) player.kickPlayer(ChatColor.DARK_RED + "You were poll-kicked."); |
There was a problem hiding this comment.
There needs to be a better explanation for the kick. Also, I would implement this via an off-record punishment so they get all the formatting.
Although, you may need to make sure off-record punishments, instead of saying ...appeal here... they say ...punishment does not count... or something.
HuManKeat
left a comment
There was a problem hiding this comment.
That's a job well done on its own, I only have some little things here and there, but thanks for picking up after me :)
|
|
||
| private String text; | ||
|
|
||
| @AssistedInject PollCustom(@Assisted String text, @Assisted CommandSender initiator, PollManager pollManager, Audiences audiences) { |
There was a problem hiding this comment.
The Poll class already defines an @Injected constructor, I believe @AssistedInject is correct here
| } | ||
|
|
||
| private final Player player; | ||
| private final PlayerId player; |
| public void executeAction() { | ||
| PlayerId kicked = userStore.playerId(player); | ||
| punishmentCreator.create(null, kicked, "The poll to kick " + kicked.username() + " succeeded", PunishmentDoc.Type.KICK, null, false, false, true); | ||
| punishmentCreator.create(null, player, "The poll to kick " + player.username() + " succeeded", PunishmentDoc.Type.KICK, null, false, false, true); |
There was a problem hiding this comment.
Maybe make this translatable instead of a hardcoded string
There was a problem hiding this comment.
Well, It doesn't really make sense to translate a punishment message, as it cannot be translated per user.
| @Override | ||
| public String getActionString() { | ||
| return normalize + "Kick: " + boldAqua + this.player; | ||
| return normalize + "Kick: " + boldAqua + this.player.username(); |
There was a problem hiding this comment.
Same here, would prefer a translatable component.
| } | ||
|
|
||
| if (!Config.Poll.enabled()) { | ||
| if(!Config.Poll.enabled()) { |
There was a problem hiding this comment.
Can you let the poll package have its own configuration class? I think it would be better than referencing it from the Config class.
|
|
||
| private String text; | ||
|
|
||
| @AssistedInject PollCustom(@Assisted String text, @Assisted CommandSender initiator, PollManager pollManager, Audiences audiences) { |
There was a problem hiding this comment.
The Poll class already defines an @Injected constructor, I believe @AssistedInject is correct here
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| public class PollCommands implements Commands { |
| huddle.globalChatDisabled = Global chat is disabled during team huddle No newline at end of file | ||
| huddle.globalChatDisabled = Global chat is disabled during team huddle | ||
|
|
||
| poll.vote.value.invalid = Accepted values: yes|no |
| public static String boldAqua = ChatColor.BOLD + "" + ChatColor.AQUA; | ||
| public static String normalize = ChatColor.RESET + "" + ChatColor.DARK_AQUA; | ||
| public static String seperator = ChatColor.RESET + " | "; | ||
| public static String separator = ChatColor.RESET + " | "; |
| final PluginFacetBinder facets = new PluginFacetBinder(binder()); | ||
| facets.register(PollCommands.class); | ||
| facets.register(PollManager.class); | ||
| facets.register(PollListener.class); |
| PlayerId voter = CommandUtils.senderToMatchPlayer(sender).getPlayerId(); | ||
| Poll currentPoll = pollManager.getPoll(); | ||
| if(currentPoll != null) { | ||
| if(args.getString(0).equalsIgnoreCase("yes")) { |
There was a problem hiding this comment.
Maybe have a cleaner way to deal with values. Perhaps use an enum to hold the possible values of a vote.
There was a problem hiding this comment.
I think the check is fine. Polls, at least for now, are either yes or no.
| public void veto(CommandContext args, CommandSender sender) throws CommandException { | ||
| if(pollManager.isPollRunning()) { | ||
| pollManager.endPoll(PollEndReason.Cancelled); | ||
| audiences.localServer().sendMessage(new Component(ChatColor.RED).translate("poll.veto", new PlayerComponent(identityProvider.currentIdentity(sender)))); |
There was a problem hiding this comment.
preferably make this 2 lines instead of one for visibility
| Player initiator = tc.oc.commons.bukkit.commands.CommandUtils.senderToPlayer(sender); | ||
| Player player = tc.oc.commons.bukkit.commands.CommandUtils.findOnlinePlayer(args, sender, 0); | ||
|
|
||
| if(player.hasPermission("pgm.poll.kick.exempt") && !initiator.hasPermission("pgm.poll.kick.override")) { |
There was a problem hiding this comment.
Declare the permission strings as a constant at the top of the class, just so other classes may use it for whatever purposes
| return StringUtils.complete(args.getSuggestionContext().getPrefix(), mutationQueue.mutationsAvailable().stream().map(mutation -> mutation.name().toLowerCase())); | ||
| } | ||
|
|
||
| if(!Config.Poll.enabled()) { |
There was a problem hiding this comment.
have a class to hold the configuration values, i.e. a specific PollConfiguration
2359476 to
f5c8438
Compare
f5c8438 to
01173c4
Compare
| parts.add(new Component(new TranslatableComponent("punishment.screen.rules", Links.rulesLink()))); | ||
|
|
||
| parts.add(new Component(new TranslatableComponent("punishment.screen.appeal", Links.appealLink()))); | ||
| if (!punishment.off_record()) { |
There was a problem hiding this comment.
if(punishment.off_record()) {
// parts.add("off_record");
} else {
// parts.add("others");
}| if (lines == null) return; | ||
| ImmutableList.Builder<PGMMap> maps = ImmutableList.builder(); | ||
| for(String line : lines) { | ||
| if (line.contains("#")) { |
| PlayerId voter = CommandUtils.senderToMatchPlayer(sender).getPlayerId(); | ||
| Poll currentPoll = pollManager.getPoll(); | ||
| if(currentPoll != null) { | ||
| if(args.getString(0).equalsIgnoreCase("yes")) { |
There was a problem hiding this comment.
I think the check is fine. Polls, at least for now, are either yes or no.
| this.pollConfig = pollConfig; | ||
| } | ||
|
|
||
|
|
| ) | ||
| @CommandPermissions("poll.kick") | ||
| public void pollKick(CommandContext args, CommandSender sender) throws CommandException { | ||
| Player initiator = tc.oc.commons.bukkit.commands.CommandUtils.senderToPlayer(sender); |
There was a problem hiding this comment.
Might want to consider statically importing the sendToPlayer method since you use it frequently.
| @CommandPermissions("poll.next") | ||
| public List<String> pollNext(CommandContext args, CommandSender sender) throws CommandException { | ||
| final String mapName = args.argsLength() > 0 ? args.getJoinedStrings(0) : ""; | ||
| if(args.getSuggestionContext() != null) { |
There was a problem hiding this comment.
All of these single-if checks can just be put as one-liners.
if(args.getSuggestionContext() != null) return CommandUtils.completeMapName(mapName);
if(!pollConfig.enabled()) throw new TranslatableCommandException("poll.disabled");
// etc...| throw new TranslatableCommandException("poll.map.notallowed"); | ||
| } | ||
|
|
||
| if(onlinePlayers.count() * 4 / 5 > nextMap.getDocument().max_players() && !sender.hasPermission("poll.next.override")) { |
There was a problem hiding this comment.
What's the reasoning behind the 4/5ths? Is there a standard place we can put this logic? If a match is too full?
| } | ||
|
|
||
| if(onlinePlayers.count() * 4 / 5 > nextMap.getDocument().max_players() && !sender.hasPermission("poll.next.override")) { | ||
| throw new TranslatableCommandException("poll.map.toomanyplayers"); |
There was a problem hiding this comment.
For translation keys, use camel case for multi-words:
poll.map.tooManyPlayers
| public String getDescriptionMessage() { | ||
| return boldAqua + text; | ||
| } | ||
| } No newline at end of file |
| public class PollNextMap extends Poll { | ||
|
|
||
| public interface Factory { | ||
| PollNextMap create(CommandSender sender, PGMMap nextMap, PlayerId playerId); |
There was a problem hiding this comment.
If the CommandSender is the same as the PlayerId, maybe just provide the sender and derive the player? or the other way around?
There was a problem hiding this comment.
I say that because when instantiating this factory, the senderToPlayer method is invoked frequently, and might just be more useful to be put inside the construction.
This partially fixes StratusNetwork/issues#248
Adds buy permission Actually mounts the player Disallows broken versions Removes entity on disconnect/dismount
No description provided.