Skip to content
This repository was archived by the owner on Nov 25, 2019. It is now read-only.

Commit 01173c4

Browse files
committed
Improve polls some more
1 parent 3c74a30 commit 01173c4

10 files changed

Lines changed: 89 additions & 57 deletions

File tree

Commons/core/src/main/i18n/templates/pgm/PGMErrors.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ rating.sameRating = You have already rated this map a {0}.
137137

138138
huddle.globalChatDisabled = Global chat is disabled during team huddle
139139

140-
poll.vote.value.invalid = Accepted values: yes|no
140+
poll.vote.invalidValue = Accepted values: yes|no
141141
poll.noPollRunning = There is currently no poll running!
142142
poll.kick.exempt = You cannot poll kick this player!
143143
poll.disabled = Polls are disabled on this server!

PGM/src/main/java/tc/oc/pgm/Config.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,6 @@ public static double setNextTokenChange() {
5959

6060
}
6161

62-
public static class Poll {
63-
public static Path getPollAbleMapPath() {
64-
Path pollPath = Paths.get(getConfiguration().getString("poll.maps.path", "default.txt"));
65-
if(!pollPath.isAbsolute()) pollPath = PGM.getMatchManager().getPluginDataFolder().resolve(pollPath);
66-
return pollPath;
67-
}
68-
69-
public static boolean enabled() {
70-
return getConfiguration().getBoolean("poll.enabled", true);
71-
}
72-
}
73-
7462
public static class Broadcast {
7563
public static boolean title() {
7664
return getConfiguration().getBoolean("broadcast.title", true);

PGM/src/main/java/tc/oc/pgm/polls/Poll.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
public abstract class Poll implements Runnable {
1313

14-
public static String boldAqua = ChatColor.BOLD + "" + ChatColor.AQUA;
15-
public static String normalize = ChatColor.RESET + "" + ChatColor.DARK_AQUA;
16-
public static String separator = ChatColor.RESET + " | ";
14+
public static final String boldAqua = ChatColor.BOLD + "" + ChatColor.AQUA;
15+
public static final String normalize = ChatColor.RESET + "" + ChatColor.DARK_AQUA;
16+
public static final String separator = ChatColor.RESET + " | ";
1717

1818
protected final PollManager pollManager;
1919
protected final PlayerId initiator;

PGM/src/main/java/tc/oc/pgm/polls/PollBlacklist.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.google.common.collect.ImmutableList;
55
import com.google.inject.Inject;
66
import com.google.inject.Singleton;
7+
import tc.oc.commons.core.logging.Loggers;
78
import tc.oc.commons.core.plugin.PluginFacet;
8-
import tc.oc.pgm.Config;
99
import tc.oc.pgm.PGM;
1010
import tc.oc.pgm.map.MapId;
1111
import tc.oc.pgm.map.MapLibrary;
@@ -17,16 +17,21 @@
1717
import java.util.ArrayList;
1818
import java.util.List;
1919
import java.util.Optional;
20+
import java.util.logging.Logger;
2021

2122
@Singleton
2223
public class PollBlacklist implements PluginFacet {
2324

24-
private List<MapId> blacklistedMaps = new ArrayList<>();
25+
private List<PGMMap> blacklistedMaps = new ArrayList<>();
2526

2627
private final MapLibrary mapLibrary;
28+
private final PollConfig pollConfig;
29+
private final Logger logger;
2730

28-
@Inject PollBlacklist(MapLibrary mapLibrary) {
31+
@Inject PollBlacklist(MapLibrary mapLibrary, PollConfig pollConfig, Loggers loggers) {
2932
this.mapLibrary = mapLibrary;
33+
this.pollConfig = pollConfig;
34+
this.logger = loggers.get(getClass());
3035
}
3136

3237
@Override
@@ -35,34 +40,37 @@ public void enable() {
3540
}
3641

3742
public void loadPollBlacklist() {
38-
Path filepath = Config.Poll.getPollAbleMapPath();
43+
Path filepath = pollConfig.getPollBlacklistPath();
3944
if (filepath == null) return;
4045
List<String> lines = null;
4146
try {
4247
lines = Files.readAllLines(filepath, Charsets.UTF_8);
4348
} catch (IOException e) {
44-
PGM.get().getLogger().severe("Error in reading poll blacklist from file!");
49+
logger.severe("Error in reading poll blacklist from file!");
4550
}
4651
if (lines == null) return;
47-
ImmutableList.Builder<MapId> maps = ImmutableList.builder();
52+
ImmutableList.Builder<PGMMap> maps = ImmutableList.builder();
4853
for(String line : lines) {
54+
if (line.contains("#")) {
55+
line = line.substring(0, line.indexOf("#"));
56+
}
57+
4958
line = line.trim();
5059
if(line.isEmpty()) {
5160
continue;
5261
}
5362

5463
Optional<PGMMap> map = mapLibrary.getMapByNameOrId(line);
5564
if(map.isPresent()) {
56-
maps.add(map.get().getId());
65+
maps.add(map.get());
5766
} else {
58-
mapLibrary.getLogger().severe("Unknown map '" + line
59-
+ "' when parsing " + filepath.toString());
67+
logger.warning("Unknown map '" + line + "' when parsing " + filepath.toString());
6068
}
6169
}
6270
this.blacklistedMaps = maps.build();
6371
}
6472

6573
public boolean isBlacklisted(PGMMap map) {
66-
return blacklistedMaps.contains(map.getId());
74+
return blacklistedMaps.contains(map);
6775
}
6876
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package tc.oc.pgm.polls;
2+
3+
import org.bukkit.configuration.ConfigurationSection;
4+
import tc.oc.pgm.PGM;
5+
import tc.oc.pgm.match.MatchManager;
6+
7+
import javax.inject.Inject;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
11+
import static com.google.common.base.Preconditions.checkNotNull;
12+
13+
public class PollConfig {
14+
15+
private final ConfigurationSection config;
16+
private final MatchManager matchManager;
17+
18+
@Inject PollConfig(ConfigurationSection config, MatchManager matchManager) {
19+
this.config = checkNotNull(config.getConfigurationSection("poll"));
20+
this.matchManager = matchManager;
21+
}
22+
23+
public Path getPollBlacklistPath() {
24+
Path pollPath = Paths.get(config.getString("maps.path", "default.txt"));
25+
if(!pollPath.isAbsolute()) {
26+
pollPath = matchManager.getPluginDataFolder().resolve(pollPath);
27+
}
28+
return pollPath;
29+
}
30+
31+
public boolean enabled() {
32+
return config.getBoolean("enabled", true);
33+
}
34+
35+
}

PGM/src/main/java/tc/oc/pgm/polls/PollListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import tc.oc.commons.core.plugin.PluginFacet;
99
import tc.oc.pgm.polls.event.PollEndEvent;
1010

11-
public class PollListener implements PluginFacet, Listener {
11+
public class PollListener implements Listener {
1212

1313
private final Audiences audiences;
1414

PGM/src/main/java/tc/oc/pgm/polls/PollManifest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package tc.oc.pgm.polls;
22

33
import com.google.inject.assistedinject.FactoryModuleBuilder;
4+
import tc.oc.commons.core.commands.CommandBinder;
45
import tc.oc.commons.core.inject.HybridManifest;
56
import tc.oc.commons.core.plugin.PluginFacetBinder;
7+
import tc.oc.minecraft.api.event.ListenerBinder;
68
import tc.oc.pgm.polls.commands.PollCommands;
79
import tc.oc.pgm.polls.types.PollCustom;
810
import tc.oc.pgm.polls.types.PollKick;
@@ -21,9 +23,11 @@ protected void configure() {
2123
install(fmb.build(PollMutation.Factory.class));
2224

2325
final PluginFacetBinder facets = new PluginFacetBinder(binder());
24-
facets.register(PollCommands.class);
2526
facets.register(PollManager.class);
26-
facets.register(PollListener.class);
2727
facets.register(PollBlacklist.class);
28+
29+
new CommandBinder(binder()).register(PollCommands.class);
30+
31+
new ListenerBinder(binder()).bindListener().to(PollListener.class);
2832
}
2933
}

PGM/src/main/java/tc/oc/pgm/polls/commands/PollCommands.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
import com.sk89q.minecraft.util.commands.NestedCommand;
88
import net.md_5.bungee.api.ChatColor;
99
import org.bukkit.command.CommandSender;
10-
import org.bukkit.entity.Player;
1110
import tc.oc.api.docs.PlayerId;
1211
import tc.oc.commons.bukkit.chat.PlayerComponent;
1312
import tc.oc.commons.bukkit.nick.IdentityProvider;
1413
import tc.oc.commons.core.chat.Audiences;
1514
import tc.oc.commons.core.chat.Component;
16-
import tc.oc.commons.core.commands.Commands;
1715
import tc.oc.commons.core.commands.TranslatableCommandException;
1816
import tc.oc.pgm.commands.CommandUtils;
1917
import tc.oc.pgm.polls.Poll;
@@ -22,7 +20,7 @@
2220

2321
import javax.inject.Inject;
2422

25-
public class PollCommands implements Commands {
23+
public class PollCommands {
2624

2725
private final PollManager pollManager;
2826
private final IdentityProvider identityProvider;
@@ -63,7 +61,7 @@ public void vote(CommandContext args, CommandSender sender) throws CommandExcept
6361
currentPoll.voteAgainst(voter);
6462
sender.sendMessage(new Component(ChatColor.RED).translate("poll.vote.against"));
6563
} else {
66-
throw new TranslatableCommandException("poll.vote.value.invalid");
64+
throw new TranslatableCommandException("poll.vote.invalidValue");
6765
}
6866
} else {
6967
throw new TranslatableCommandException("poll.noPollRunning");

PGM/src/main/java/tc/oc/pgm/polls/commands/PollSubCommands.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,20 @@
1313
import tc.oc.commons.core.commands.TranslatableCommandException;
1414
import tc.oc.commons.core.formatting.StringUtils;
1515
import tc.oc.commons.core.restart.RestartManager;
16-
import tc.oc.pgm.Config;
1716
import tc.oc.pgm.commands.CommandUtils;
1817
import tc.oc.pgm.map.PGMMap;
1918
import tc.oc.pgm.match.MatchManager;
2019
import tc.oc.pgm.mutation.Mutation;
2120
import tc.oc.pgm.mutation.MutationQueue;
22-
import tc.oc.pgm.mutation.command.MutationCommands;
2321
import tc.oc.pgm.polls.PollBlacklist;
22+
import tc.oc.pgm.polls.PollConfig;
2423
import tc.oc.pgm.polls.types.PollCustom;
2524
import tc.oc.pgm.polls.types.PollKick;
2625
import tc.oc.pgm.polls.PollManager;
2726
import tc.oc.pgm.polls.types.PollMutation;
2827
import tc.oc.pgm.polls.types.PollNextMap;
2928

3029
import javax.inject.Inject;
31-
import java.util.Collection;
3230
import java.util.List;
3331

3432
public class PollSubCommands {
@@ -44,19 +42,21 @@ public class PollSubCommands {
4442
private final UserStore userStore;
4543
private final OnlinePlayers onlinePlayers;
4644
private final MatchManager matchManager;
45+
private final PollConfig pollConfig;
4746

4847
@Inject
4948
PollSubCommands(RestartManager restartManager,
50-
MutationQueue mutationQueue,
51-
PollManager pollManager,
52-
PollCustom.Factory pollCustomFactory,
53-
PollNextMap.Factory pollMapFactory,
54-
PollMutation.Factory pollMutationFactory,
55-
PollKick.Factory pollKickFactory,
56-
PollBlacklist pollBlacklist,
57-
UserStore userStore,
58-
OnlinePlayers onlinePlayers,
59-
MatchManager matchManager) {
49+
MutationQueue mutationQueue,
50+
PollManager pollManager,
51+
PollCustom.Factory pollCustomFactory,
52+
PollNextMap.Factory pollMapFactory,
53+
PollMutation.Factory pollMutationFactory,
54+
PollKick.Factory pollKickFactory,
55+
PollBlacklist pollBlacklist,
56+
UserStore userStore,
57+
OnlinePlayers onlinePlayers,
58+
MatchManager matchManager,
59+
PollConfig pollConfig) {
6060
this.restartManager = restartManager;
6161
this.mutationQueue = mutationQueue;
6262
this.pollManager = pollManager;
@@ -68,6 +68,7 @@ public class PollSubCommands {
6868
this.userStore = userStore;
6969
this.onlinePlayers = onlinePlayers;
7070
this.matchManager = matchManager;
71+
this.pollConfig = pollConfig;
7172
}
7273

7374

@@ -105,7 +106,7 @@ public List<String> pollNext(CommandContext args, CommandSender sender) throws C
105106
return CommandUtils.completeMapName(mapName);
106107
}
107108

108-
if(!Config.Poll.enabled()) {
109+
if(!pollConfig.enabled()) {
109110
throw new TranslatableCommandException("poll.disabled");
110111
}
111112

@@ -147,7 +148,7 @@ public List<String> pollMutation(CommandContext args, CommandSender sender) thro
147148
return StringUtils.complete(args.getSuggestionContext().getPrefix(), mutationQueue.mutationsAvailable().stream().map(mutation -> mutation.name().toLowerCase()));
148149
}
149150

150-
if(!Config.Poll.enabled()) {
151+
if(!pollConfig.enabled()) {
151152
throw new TranslatableCommandException("poll.disabled");
152153
}
153154

@@ -161,7 +162,7 @@ public List<String> pollMutation(CommandContext args, CommandSender sender) thro
161162
if(mutation == null) {
162163
throw new TranslatableCommandException("command.mutation.error.find", mutationString);
163164
} else if(mutationQueue.mutations().contains(mutation)) {
164-
throw new TranslatableCommandException(true ? "command.mutation.error.enabled" : "command.mutation.error.disabled", mutation.getComponent(net.md_5.bungee.api.ChatColor.RED));
165+
throw new TranslatableCommandException("command.mutation.error.enabled", mutation.getComponent(net.md_5.bungee.api.ChatColor.RED));
165166
} else if(!mutation.isPollable() && !sender.hasPermission("poll.mutation.override")) {
166167
throw new TranslatableCommandException("command.mutation.error.illegal", mutationString);
167168
}

PGM/src/main/java/tc/oc/pgm/polls/types/PollKick.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,30 @@ public interface Factory {
2121
PollKick create(PlayerId initiator, Player player);
2222
}
2323

24-
private final PlayerId player;
24+
private final PlayerId playerId;
2525
private final IdentityProvider identityProvider;
2626
private final PunishmentCreator punishmentCreator;
27-
private final UserStore userStore;
2827

2928
@AssistedInject PollKick(@Assisted PlayerId initiator, @Assisted Player player, PollManager pollManager, Audiences audiences, IdentityProvider identityProvider, PunishmentCreator punishmentCreator, UserStore userStore) {
3029
super(pollManager, initiator, audiences);
3130
this.identityProvider = identityProvider;
3231
this.punishmentCreator = punishmentCreator;
33-
this.userStore = userStore;
34-
this.player = userStore.playerId(player);
32+
this.playerId = userStore.playerId(player);
3533
}
3634

3735
@Override
3836
public void executeAction() {
39-
punishmentCreator.create(null, player, "The poll to kick " + player.username() + " succeeded", PunishmentDoc.Type.KICK, null, false, false, true);
40-
audiences.localServer().sendMessage(new Component(ChatColor.DARK_AQUA).translate("poll.kick.success", new PlayerComponent(identityProvider.currentIdentity(player))));
37+
punishmentCreator.create(null, playerId, "The poll to kick " + playerId.username() + " succeeded", PunishmentDoc.Type.KICK, null, false, false, true);
38+
audiences.localServer().sendMessage(new Component(ChatColor.DARK_AQUA).translate("poll.kick.success", new PlayerComponent(identityProvider.currentIdentity(playerId))));
4139
}
4240

4341
@Override
4442
public String getActionString() {
45-
return normalize + "Kick: " + boldAqua + this.player.username();
43+
return normalize + "Kick: " + boldAqua + this.playerId.username();
4644
}
4745

4846
@Override
4947
public String getDescriptionMessage() {
50-
return "to kick " + boldAqua + this.player.username();
48+
return "to kick " + boldAqua + this.playerId.username();
5149
}
5250
}

0 commit comments

Comments
 (0)