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

Check FireTick during match load and start #879

Merged
merged 25 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0a70ecc
Check FireTick during match load and start
CoWinkKeyDinkInc May 27, 2021
e072f9e
Disable fire spread when match ends
CoWinkKeyDinkInc May 27, 2021
ed4d0fa
Evaluate original map setting of doFireTick
CoWinkKeyDinkInc May 27, 2021
5c68abb
Add additional checker
CoWinkKeyDinkInc May 28, 2021
8cd810f
Store gamerules from level.dat, simplify FireTick evaluation
CoWinkKeyDinkInc Jun 8, 2021
753150e
reformat code
CoWinkKeyDinkInc Jun 8, 2021
02ac7ae
Merge branch 'dev' into fix-fire
CoWinkKeyDinkInc Jun 8, 2021
848fc58
Rename String values
CoWinkKeyDinkInc Jun 8, 2021
8ba37e4
Merge branch 'fix-fire' of github.com:CoWinkKeyDinkInc/PGM into fix-fire
CoWinkKeyDinkInc Jun 8, 2021
76ab092
Simplify evaluation
CoWinkKeyDinkInc Jun 9, 2021
005d4e4
Add gamerule values from level.dat into GameRulesMatchModule, adjust …
CoWinkKeyDinkInc Jun 12, 2021
6fe2a9b
Simplify evaluation
CoWinkKeyDinkInc Jun 12, 2021
1163ae6
Merge branch 'dev' into fix-fire
CoWinkKeyDinkInc Jun 12, 2021
1035c6e
Fix daylightcycle evaluation
CoWinkKeyDinkInc Jun 13, 2021
bf743a2
Remove getGameRules function
CoWinkKeyDinkInc Jun 13, 2021
0df51cb
Merge branch 'dev' into fix-fire
CoWinkKeyDinkInc Jul 9, 2021
50d0871
Add epic comment
CoWinkKeyDinkInc Jul 16, 2021
00ac84e
Add GameRule eneum, update PGMListener to work with eneum
CoWinkKeyDinkInc Jul 16, 2021
ba42dcf
Fix Comment
CoWinkKeyDinkInc Jul 16, 2021
68675b3
Merge branch 'dev' into fix-fire
CoWinkKeyDinkInc Jul 31, 2021
ab0c1c3
Fix evaluation of gamemodes from level.dat and XML
CoWinkKeyDinkInc Aug 3, 2021
3ddaf10
Merge branch 'fix-fire' of github.com:CoWinkKeyDinkInc/PGM into fix-fire
CoWinkKeyDinkInc Aug 3, 2021
b3a397e
Fix application order of gamerules in XML
CoWinkKeyDinkInc Aug 28, 2021
038a74b
Merge branch 'dev' into fix-fire
CoWinkKeyDinkInc Aug 28, 2021
84caf3d
Add functions for timesetting
CoWinkKeyDinkInc Aug 29, 2021
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 @@ -10,6 +10,7 @@ public class GameRulesMatchModule implements MatchModule {

private final Match match;
private final Map<String, String> gameRules;
private boolean doDaylightCycle = false;
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved

public GameRulesMatchModule(Match match, Map<String, String> gameRules) {
this.match = match;
Expand All @@ -20,10 +21,29 @@ public GameRulesMatchModule(Match match, Map<String, String> gameRules) {
public void load() {
for (Map.Entry<String, String> gameRule : this.gameRules.entrySet()) {
this.match.getWorld().setGameRuleValue(gameRule.getKey(), gameRule.getValue());
if (gameRule.getKey().equals("doDaylightCycle")) {
doDaylightCycle = Boolean.parseBoolean(gameRule.getValue());
}
}

// gets gamerule values from level.dat after being set
// does not save doDaylightCycle to gamerules
for (String gameRule : this.match.getWorld().getGameRules()) {
if (!gameRule.equals("doDaylightCycle")) {
gameRules.put(gameRule, this.match.getWorld().getGameRuleValue(gameRule));
}
}
}

public ImmutableMap<String, String> getGameRules() {
return ImmutableMap.copyOf(gameRules);
}

public String getGameRule(String gameRule) {
return gameRules.get(gameRule);
}

public boolean getDoDaylightCycle() {
return doDaylightCycle;
}
}
29 changes: 25 additions & 4 deletions core/src/main/java/tc/oc/pgm/listeners/PGMListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import tc.oc.pgm.util.text.TextTranslations;

public class PGMListener implements Listener {
private static final String DO_FIRE_TICK = "doFireTick";
private static final String DO_DAYLIGHT_CYCLE = "doDaylightCycle";
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved
/*
1000 /time set day
Expand Down Expand Up @@ -258,6 +259,26 @@ public void handleItemPickup(final PlayerPickupItemEvent event) {
if (nearestPlayer != event.getPlayer()) event.setCancelled(true);
}

@EventHandler
public void lockFireTick(final MatchLoadEvent event) {
event.getMatch().getWorld().setGameRuleValue(DO_FIRE_TICK, Boolean.toString(false));
}

@EventHandler
public void unlockFireTick(final MatchStartEvent event) {
event
.getMatch()
.getWorld()
.setGameRuleValue(
DO_FIRE_TICK,
event.getMatch().needModule(GameRulesMatchModule.class).getGameRule(DO_FIRE_TICK));
}

@EventHandler
public void lockFireTick(final MatchFinishEvent event) {
event.getMatch().getWorld().setGameRuleValue(DO_FIRE_TICK, Boolean.toString(false));
}

//
// Time Lock
// lock time before, during (if time lock enabled), and after the match
Expand All @@ -272,11 +293,11 @@ public void unlockTime(final MatchStartEvent event) {
// if there is a timelock module and it is off, unlock time
boolean unlockTime = !event.getMatch().getModule(WorldTimeModule.class).isTimeLocked();
CoWinkKeyDinkInc marked this conversation as resolved.
Show resolved Hide resolved

GameRulesMatchModule gameRulesModule = event.getMatch().getModule(GameRulesMatchModule.class);
if (gameRulesModule != null && gameRulesModule.getGameRules().containsKey(DO_DAYLIGHT_CYCLE)) {
unlockTime = Boolean.parseBoolean(gameRulesModule.getGameRules().get(DO_DAYLIGHT_CYCLE));
GameRulesMatchModule gameRulesMatchModule =
event.getMatch().getModule(GameRulesMatchModule.class);
if (gameRulesMatchModule != null && gameRulesMatchModule.getDoDaylightCycle()) {
unlockTime = gameRulesMatchModule.getDoDaylightCycle();
}

event.getMatch().getWorld().setGameRuleValue(DO_DAYLIGHT_CYCLE, Boolean.toString(unlockTime));
}

Expand Down