-
Notifications
You must be signed in to change notification settings - Fork 14
Cleanup polls code #67
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the 4/5ths
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing a text object, can that just be a method?
getReasonString()
or getPollString()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Poll
class already defines an @Inject
ed constructor, I believe @AssistedInject
is correct here
@@ -21,33 +21,32 @@ | |||
PollKick create(PlayerId initiator, Player player); | |||
} | |||
|
|||
private final Player player; | |||
private final PlayerId player; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be named playerId
} | ||
|
||
@Override | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make this translatable instead of a hardcoded string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, It doesn't really make sense to translate a punishment message, as it cannot be translated per user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about translations?
audiences.localServer().sendMessage(new Component(ChatColor.DARK_AQUA).translate("poll.kick.success", new PlayerComponent(identityProvider.currentIdentity(player)))); | ||
} | ||
|
||
@Override | ||
public String getActionString() { | ||
return normalize + "Kick: " + boldAqua + this.player; | ||
return normalize + "Kick: " + boldAqua + this.player.username(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, would prefer a translatable component.
@@ -94,34 +105,31 @@ public void pollKick(CommandContext args, CommandSender sender) throws CommandEx | |||
return CommandUtils.completeMapName(mapName); | |||
} | |||
|
|||
if (!Config.Poll.enabled()) { | |||
if(!Config.Poll.enabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Poll
class already defines an @Inject
ed constructor, I believe @AssistedInject
is correct here
|
||
import javax.inject.Inject; | ||
|
||
public class PollCommands implements Commands { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a CommandBinder
huddle.globalChatDisabled = Global chat is disabled during team huddle | ||
|
||
poll.vote.value.invalid = Accepted values: yes|no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poll.vote.invalidValue
|
||
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 + " | "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constant
final PluginFacetBinder facets = new PluginFacetBinder(binder()); | ||
facets.register(PollCommands.class); | ||
facets.register(PollManager.class); | ||
facets.register(PollListener.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bindListener
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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("#")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the check is fine. Polls, at least for now, are either yes or no.
this.pollConfig = pollConfig; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra new lines here
) | ||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For translation keys, use camel case for multi-words:
poll.map.tooManyPlayers
public String getDescriptionMessage() { | ||
return boldAqua + text; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line
|
||
public class PollNextMap extends Poll { | ||
|
||
public interface Factory { | ||
PollNextMap create(CommandSender sender, PGMMap nextMap, PlayerId playerId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.