Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rotations #114

Merged
merged 41 commits into from Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c62cc45
Fix single child union region parsing
Pugzy Nov 17, 2019
2889f2c
Correct map on cycle
chatasma Nov 25, 2019
dc819c2
Implement a rotations system
Dec 7, 2019
da56cf0
Add the rotation commands
Dec 8, 2019
b83b2ad
Fix NPE on projectile source within ModifyBowProjectile module
botinator Dec 9, 2019
8d87bca
Readd entities in modify bow projectile, and fix enderpearls
Pablete1234 Dec 10, 2019
d1bfdb9
Fix NMS issue that prevented villager trades, Resolves #101
botinator Dec 11, 2019
b1578e2
Improve rotations' integration to the codebase
Dec 13, 2019
703224b
Add a line ending
Dec 13, 2019
1b54e63
Make Rotations return an immutable collection of their maps
Dec 13, 2019
c1156a3
Make RotationManager only set it's rotation once & log it's errors pr…
Dec 13, 2019
e67fc84
Save optional maps into a variable when loading rotations
Dec 13, 2019
140e796
Make rotation update messages translatable
Dec 13, 2019
6e33fe1
Log rotation position saving errors properly
Dec 13, 2019
4f7a19b
Randomize FFA spawns of equal distance
Pugzy Dec 15, 2019
1af61f7
Change plugin prefix from PGMImpl to PGM
Electroid Dec 15, 2019
5bd06d7
Clarify that PGM.GLOBAL, not PGM.get() is deprecated
Electroid Dec 15, 2019
7ed5d16
Update deployment files with newer JVM
Electroid Dec 15, 2019
849f54f
Reduce rotation command aliases
Dec 15, 2019
4842c1b
Translate the skip command's success message
Dec 15, 2019
291fee0
Add a delay to 1.13 auto completion
Dec 15, 2019
6d95947
Make rotation's player count equation less cryptic & stop using PGM.G…
Dec 16, 2019
cd1b0d0
Remove some pointless methods for rotations
Dec 16, 2019
1f72ea8
Fetch and cache UUIDs from Contributor
Meeples10 Dec 16, 2019
6190619
Rotations now save their next map in a string (next_map) within rotat…
Dec 16, 2019
f093587
Refactor & re-structure rotations
Dec 17, 2019
852374b
Fix typo
Dec 17, 2019
e3dca2a
Fix old match folder not deleting on cycle
botinator Dec 17, 2019
983ad75
Remove '_' from variables, & erase infiltrated debug line
Dec 17, 2019
dcbd4f5
oops, forgot to run the code formatting test
Dec 17, 2019
7aa8986
Allow the return of a null next map on PGMMapProvider
Dec 17, 2019
b7b24dc
Annottate next map as Nullable in CycleMatchModule
Dec 17, 2019
d3cd482
Simplify rotations manager's popNextMap logic
Dec 17, 2019
f59822f
Fix & improve Rotations internal logic
Dec 18, 2019
59af409
Contemplate that there may not be a next map for /next
Dec 18, 2019
a36df4d
Make RandomPGMMapOrder able to track if a map has been /setnext
Dec 18, 2019
4d14310
Clear best spawn points when farther one found
Pugzy Dec 17, 2019
a259a15
Final tweaks to rotation's logic
Dec 18, 2019
d141949
Merge branch 'master' into master
BGMP Dec 18, 2019
51c8f44
Final formatting
Dec 18, 2019
1a8d2d6
Simplify rotation's internal logic
Dec 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/i18n/templates/pgm/PGMMessages.properties
Expand Up @@ -23,6 +23,7 @@ command.admin.pgm = Configuration successfully reloaded.

# {0} = map title and version
command.map.next.success = Next map: {0}
command.map.next.noNextMap = No next map

command.map.update.running = Not updated, map modified by active match

Expand Down
12 changes: 10 additions & 2 deletions src/main/i18n/templates/pgm/PGMUI.properties
Expand Up @@ -16,9 +16,17 @@ command.map.mapInfo.proto = Proto
command.map.mapInfo.source = Source
command.map.mapInfo.folder = Folder

command.map.currentRotation.title = Current Rotation
command.rotation.noRotationMatch = No rotations matched query.
command.rotation.noRotation = No rotation currently in use.
command.rotation.noRotations = No loaded rotations.
command.rotation.currentRotation.title = Rotation
command.rotation.rotationsDisabled = Rotations are currently disabled.

command.map.rotationList.title = Loaded Rotations
command.rotation.rotationList.title = Loaded Rotations
command.rotation.skip.message = Skipped a total of {0} positions.
command.rotation.skip.noNegative = You may not skip negative positions!

rotations.rotationChange = Rotation has been set to {0} in order to better adjust to the current player count.

map.genre.objectives = Objectives
map.genre.deathmatch = Deathmatch
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/tc/oc/pgm/Config.java
Expand Up @@ -33,6 +33,16 @@ public static boolean reloadWhenError() {
}
}

public static class Rotations {
public static boolean areEnabled() {
return getConfiguration().getBoolean("rotations.enabled");
}

public static String getPath() {
return getConfiguration().getString("rotations.path");
}
}

public static class AutoRestart {
private final Configuration config;

Expand Down
19 changes: 17 additions & 2 deletions src/main/java/tc/oc/pgm/PGMImpl.java
Expand Up @@ -45,6 +45,7 @@
import tc.oc.pgm.commands.MapDevelopmentCommands;
import tc.oc.pgm.commands.MatchCommands;
import tc.oc.pgm.commands.ModeCommands;
import tc.oc.pgm.commands.RotationCommands;
import tc.oc.pgm.commands.StartCommands;
import tc.oc.pgm.commands.TeamCommands;
import tc.oc.pgm.commands.TimeLimitCommands;
Expand Down Expand Up @@ -113,6 +114,8 @@
import tc.oc.pgm.regions.RegionModule;
import tc.oc.pgm.renewable.RenewableModule;
import tc.oc.pgm.restart.RestartManager;
import tc.oc.pgm.rotation.FixedPGMMapOrderManager;
import tc.oc.pgm.rotation.RandomPGMMapOrder;
import tc.oc.pgm.score.ScoreModule;
import tc.oc.pgm.scoreboard.ScoreboardModule;
import tc.oc.pgm.scoreboard.SidebarModule;
Expand Down Expand Up @@ -231,6 +234,15 @@ public void onEnable() {

try {
matchManager = new MatchManagerImpl(server, mapLibrary, mapLoader);

if (Config.Rotations.areEnabled()) {
matchManager.setMapOrder(
new FixedPGMMapOrderManager(
matchManager, logger, new File(getDataFolder(), Config.Rotations.getPath())));
} else {
matchManager.setMapOrder(new RandomPGMMapOrder(matchManager));
}

} catch (MapNotFoundException e) {
logger.log(Level.SEVERE, "PGM could not load any maps, server will shut down", e);
server.shutdown();
Expand Down Expand Up @@ -263,8 +275,10 @@ public Identity getIdentity(UUID playerId, String username, @Nullable String nic
.scheduleSyncDelayedTask(
this,
() -> {
if (!matchManager.cycleMatch(null, MapCommands.popNextMap(), true).isPresent()) {
logger.severe("PGM could not load the initial match, server will shut down");
if (!matchManager
.cycleMatch(null, matchManager.getMapOrder().popNextMap(), true)
.isPresent()) {
logger.severe("PGM could not load an initial match, server will shut down");
server.shutdown();
}
});
Expand Down Expand Up @@ -404,6 +418,7 @@ private void registerCommands() {
node.registerCommands(new MatchCommands());
node.registerNode("mode", "modes").registerCommands(new ModeCommands());
node.registerCommands(new TimeLimitCommands());
node.registerCommands(new RotationCommands());

new BukkitIntake(this, graph).register();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tc/oc/pgm/api/match/MatchManager.java
Expand Up @@ -11,6 +11,7 @@
import tc.oc.pgm.api.chat.Audience;
import tc.oc.pgm.map.MapNotFoundException;
import tc.oc.pgm.map.PGMMap;
import tc.oc.pgm.rotation.PGMMapOrder;

/** A manager that creates, loads, unloads, and cycles {@link Match}es. */
public interface MatchManager extends MatchPlayerResolver, Audience {
Expand Down Expand Up @@ -89,4 +90,8 @@ default Match getMatch(@Nullable CommandSender sender) {
// TODO: Move to either MapLibrary or MapLoader, this is an orthogonal concern
@Deprecated
Collection<PGMMap> loadNewMaps() throws MapNotFoundException;

void setMapOrder(PGMMapOrder pgmMapOrder);

PGMMapOrder getMapOrder();
}
5 changes: 3 additions & 2 deletions src/main/java/tc/oc/pgm/commands/AdminCommands.java
Expand Up @@ -127,7 +127,8 @@ public static void end(CommandSender sender, Match match, @Nullable @Text String
usage = "[map name]",
flags = "f",
perms = Permissions.SETNEXT)
public static void setNext(CommandSender sender, @Switch('f') boolean force, @Text PGMMap map)
public static void setNext(
CommandSender sender, @Switch('f') boolean force, @Text PGMMap map, MatchManager matchManager)
throws CommandException {
MatchManager mm = PGM.get().getMatchManager();
boolean restartQueued = RestartManager.get().isRestartRequested();
Expand All @@ -137,7 +138,7 @@ public static void setNext(CommandSender sender, @Switch('f') boolean force, @Te
AllTranslations.get().translate("command.admin.setNext.restartQueued", sender));
}

MapCommands.setNextMap(map);
matchManager.getMapOrder().setNextMap(map);

if (restartQueued) {
RestartManager.get().cancelRestart();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/tc/oc/pgm/commands/CycleCommands.java
Expand Up @@ -9,6 +9,7 @@
import tc.oc.pgm.AllTranslations;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchManager;
import tc.oc.pgm.commands.annotations.Text;
import tc.oc.pgm.cycle.CycleMatchModule;
import tc.oc.pgm.map.PGMMap;
Expand All @@ -24,6 +25,7 @@ public class CycleCommands {
public static void cycle(
CommandSender sender,
Match match,
MatchManager matchManager,
Duration countdown,
@Switch('f') boolean force,
@Default("next") @Text PGMMap map)
Expand All @@ -36,6 +38,7 @@ public static void cycle(
}

if (map != null) {
matchManager.getMapOrder().setNextMap(map);
cmm.startCountdown(countdown, map);
} else {
cmm.startCountdown(countdown);
Expand All @@ -49,8 +52,12 @@ public static void cycle(
flags = "f",
perms = Permissions.START)
public static void recycle(
CommandSender sender, Match match, Duration duration, @Switch('f') boolean force)
CommandSender sender,
Match match,
MatchManager matchManager,
Duration duration,
@Switch('f') boolean force)
throws CommandException {
cycle(sender, match, duration, force, match.getMap());
cycle(sender, match, matchManager, duration, force, match.getMap());
}
}
43 changes: 8 additions & 35 deletions src/main/java/tc/oc/pgm/commands/MapCommands.java
Expand Up @@ -18,10 +18,8 @@
import tc.oc.named.NameStyle;
import tc.oc.named.NicknameRenderer;
import tc.oc.pgm.AllTranslations;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.chat.Audience;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchManager;
import tc.oc.pgm.commands.annotations.Text;
import tc.oc.pgm.map.Contributor;
Expand All @@ -33,38 +31,6 @@

public class MapCommands {

// FIXME: This is temporary until a new rotation/vote system is determined.
private static PGMMap nextMap;

public static PGMMap peekNextMap() {
if (nextMap != null) {
return nextMap;
}

Iterator<Match> iterator = PGM.get().getMatchManager().getMatches().iterator();
PGMMap current = iterator.hasNext() ? iterator.next().getMap() : null;

List<PGMMap> maps = new ArrayList<>(PGM.get().getMapLibrary().getMaps());
PGMMap next;
do {
Collections.shuffle(maps);
next = maps.get(0);
} while (maps.size() > 1 && Objects.equals(current, next));

setNextMap(next);
return next;
}

public static void setNextMap(PGMMap map) {
nextMap = map;
}

public static PGMMap popNextMap() {
PGMMap peek = peekNextMap();
nextMap = null;
return peek;
}

@Command(
aliases = {"maplist", "maps", "ml"},
desc = "Shows the maps that are currently loaded",
Expand Down Expand Up @@ -205,7 +171,14 @@ public void map(Audience audience, CommandSender sender, @Text PGMMap map) {
aliases = {"mapnext", "mn", "nextmap", "nm", "next"},
desc = "Shows which map is coming up next")
public void next(Audience audience, CommandSender sender, MatchManager matchManager) {
final PGMMap next = peekNextMap();
final PGMMap next = matchManager.getMapOrder().getNextMap();
BGMP marked this conversation as resolved.
Show resolved Hide resolved

if (next == null) {
sender.sendMessage(
ChatColor.RED + AllTranslations.get().translate("command.map.next.noNextMap", sender));
return;
}

audience.sendMessage(
ChatColor.DARK_PURPLE
+ AllTranslations.get()
Expand Down