-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
Signed-off-by: Patrick <[email protected]>
- Loading branch information
There are no files selected for viewing
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 { | ||||
|
||||
|
@@ -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 comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
CoWinkKeyDinkInc
Author
Contributor
|
for (Element gameRulesElement : doc.getRootElement().getChildren("gamerules")) { |
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
CoWinkKeyDinkInc
Sep 7, 2021
Author
Contributor
putIfAbsent
stops this if <doDaylightCycle>
is already in the XML. This gets overwritten by the WorldTimeModule's default off setting for daylightcycle. Originally there was an if (!gamerule.equals("doDaylightCycle")
in there but Pablo wanted that removed.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
dentmaged
Sep 7, 2021
Contributor
This gets overwritten by the WorldTimeModule's default off setting for daylightcycle
only if time isn't locked.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
dentmaged
Sep 7, 2021
Contributor
gameRules.put(GameRule.DO_DAYLIGHT_CYCLE.getId(), Boolean.toString(wtm != null && !wtm.isTimeLocked()));
Move it above the for
on line 29 & remove the if
on line 35 too. That should fix level.dat
's doDaylightCycle
overriding PGM's.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
|
@@ -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); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
// | ||
// 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(); | ||
This comment has been minimized.
Sorry, something went wrong.
dentmaged
Contributor
|
||
|
||
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 | ||
|
@@ -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)); | ||
} | ||
} |
This line does nothing.