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

Ensure doDaylightCycle is set to correct value on match start #917

Merged
merged 3 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ public GameRulesMatchModule(Match match, Map<String, String> gameRules) {

@Override
public void load() {
// saves and sets gamerules from XML
// first, set doDaylightCycle according to timelock
WorldTimeModule wtm = this.match.getModule(WorldTimeModule.class);
this.match
.getWorld()
.setGameRuleValue(
GameRule.DO_DAYLIGHT_CYCLE.getId(), Boolean.toString(!wtm.isTimeLocked()));

// second, set any gamerules defined in the map's XML
// doDaylightCycle set in XML's gamerules module will take precedence over timelock
for (Map.Entry<String, String> gameRule : this.gameRules.entrySet()) {
gameRules.put(gameRule.getKey(), gameRule.getValue());
this.match.getWorld().setGameRuleValue(gameRule.getKey(), gameRule.getValue());
}

// saves gamerules from world (level.dat) as fallback
// lastly, retrieve gamerules from the map's level.dat and set them if absent
for (String gameRule : this.match.getWorld().getGameRules()) {
gameRules.putIfAbsent(gameRule, this.match.getWorld().getGameRuleValue(gameRule));
}

// if timelock is off, save doDayLightCycle as true
WorldTimeModule wtm = this.match.getModule(WorldTimeModule.class);
if (wtm != null && !wtm.isTimeLocked()) {
gameRules.put(GameRule.DO_DAYLIGHT_CYCLE.getId(), Boolean.toString(true));
}
}

public String getGameRule(String gameRule) {
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/tc/oc/pgm/gamerules/GameRulesModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tc.oc.pgm.gamerules;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
Expand All @@ -11,6 +13,7 @@
import tc.oc.pgm.api.map.factory.MapModuleFactory;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchModule;
import tc.oc.pgm.modules.WorldTimeModule;
import tc.oc.pgm.util.xml.InvalidXMLException;

public class GameRulesModule implements MapModule {
Expand All @@ -26,6 +29,11 @@ public MatchModule createMatchModule(Match match) {
}

public static class Factory implements MapModuleFactory<GameRulesModule> {
@Override
public Collection<Class<? extends MapModule>> getSoftDependencies() {
return ImmutableList.of(WorldTimeModule.class);
}

@Override
public GameRulesModule parse(MapFactory factory, Logger logger, Document doc)
throws InvalidXMLException {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/listeners/PGMListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public void unlockFireTick(final MatchStartEvent event) {

@EventHandler
public void lockFireTick(final MatchFinishEvent event) {
setGameRule(event, GameRule.DO_DAYLIGHT_CYCLE.getId(), false);
setGameRule(event, GameRule.DO_FIRE_TICK.getId(), false);
}

//
Expand Down