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 all 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
40 changes: 40 additions & 0 deletions core/src/main/java/tc/oc/pgm/api/map/GameRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tc.oc.pgm.api.map;

public enum GameRule {
DO_DAYLIGHT_CYCLE("doDaylightCycle"),
DO_FIRE_TICK("doFireTick"),
DO_MOB_LOOT("doMobLoot"),
DO_TILE_DROPS("doTileDrops"),
MOB_GRIEFING("mobGriefing"),
NATURAL_REGENERATION("naturalRegeneration");

/* Unsupported Gamerules:
doMobSpawning
keepInventory
commandBlockOutput
logAdminCommands
randomTickSpeed
reducedDebugInfo
sendCommandFeedback
showDeathMessages
*/

private final String id;

GameRule(String id) {
this.id = id;
}

public static GameRule byId(String gameRuleId) {
for (GameRule gameRule : GameRule.values()) {
if (gameRule.getId().equals(gameRuleId)) {
return gameRule;
}
}
return null;
}

public String getId() {
return id;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package tc.oc.pgm.gamerules;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import tc.oc.pgm.api.map.GameRule;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchModule;
import tc.oc.pgm.modules.WorldTimeModule;

public class GameRulesMatchModule implements MatchModule {

Expand All @@ -18,12 +19,25 @@ public GameRulesMatchModule(Match match, Map<String, String> gameRules) {

@Override
public void load() {
// saves and sets gamerules from XML
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
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 ImmutableMap<String, String> getGameRules() {
return ImmutableMap.copyOf(gameRules);
public String getGameRule(String gameRule) {
return gameRules.get(gameRule);
}
}
52 changes: 44 additions & 8 deletions core/src/main/java/tc/oc/pgm/listeners/PGMListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.event.BlockTransformEvent;
import tc.oc.pgm.api.map.GameRule;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchManager;
import tc.oc.pgm.api.match.event.MatchFinishEvent;
Expand All @@ -60,7 +61,6 @@
import tc.oc.pgm.util.text.TextTranslations;

public class PGMListener implements Listener {
private static final String DO_DAYLIGHT_CYCLE = "doDaylightCycle";
/*
1000 /time set day
6000 noon, sun is at its peak
Expand Down Expand Up @@ -258,31 +258,59 @@ public void handleItemPickup(final PlayerPickupItemEvent event) {
if (nearestPlayer != event.getPlayer()) event.setCancelled(true);
}

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

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

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

//
// Time Lock
// lock time before, during (if time lock enabled), and after the match
//
@EventHandler
public void lockTime(final MatchLoadEvent event) {
event.getMatch().getWorld().setGameRuleValue(DO_DAYLIGHT_CYCLE, Boolean.toString(false));
setGameRule(event, GameRule.DO_DAYLIGHT_CYCLE.getId(), false);
}

@EventHandler
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
&& Boolean.parseBoolean(
gameRulesMatchModule.getGameRule(GameRule.DO_DAYLIGHT_CYCLE.getId()))) {
unlockTime = true;
}

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

@EventHandler
public void lockTime(final MatchFinishEvent event) {
event.getMatch().getWorld().setGameRuleValue(DO_DAYLIGHT_CYCLE, Boolean.toString(false));
setGameRule(event, GameRule.DO_DAYLIGHT_CYCLE.getId(), false);
}

@EventHandler
Expand Down Expand Up @@ -405,4 +433,12 @@ public void storeSkinOnMatchJoin(PlayerJoinMatchEvent event) {
final MatchPlayer player = event.getPlayer();
PGM.get().getDatastore().setSkin(player.getId(), NMSHacks.getPlayerSkin(player.getBukkit()));
}

public void setGameRule(MatchLoadEvent event, String gameRule, boolean gameRuleValue) {
event.getMatch().getWorld().setGameRuleValue(gameRule, Boolean.toString(gameRuleValue));
}

public void setGameRule(MatchFinishEvent event, String gameRule, boolean gameRuleValue) {
event.getMatch().getWorld().setGameRuleValue(gameRule, Boolean.toString(gameRuleValue));
}
}