ProjectAres/PGM/src/main/java/tc/oc/pgm/gamerules/GameRulesMatchModule.java

44 lines
1.0 KiB
Java
Raw Normal View History

2017-01-30 01:43:34 +01:00
package tc.oc.pgm.gamerules;
import java.util.Map;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchModule;
2017-03-31 23:25:14 +02:00
import tc.oc.pgm.match.Repeatable;
import tc.oc.time.Time;
2017-01-30 01:43:34 +01:00
public class GameRulesMatchModule extends MatchModule {
2017-03-31 23:25:14 +02:00
private final Map<String, String> gameRules;
2017-01-30 01:43:34 +01:00
2017-03-31 23:25:14 +02:00
public GameRulesMatchModule(Match match, Map<String, String> gameRules) {
2017-01-30 01:43:34 +01:00
super(match);
this.gameRules = Preconditions.checkNotNull(gameRules, "gamerules");
}
@Override
public void load() {
2017-03-31 23:25:14 +02:00
update();
2017-01-30 01:43:34 +01:00
}
2017-03-31 23:25:14 +02:00
@Repeatable(interval = @Time(seconds = 1))
public void tick() {
update();
2017-01-30 01:43:34 +01:00
}
2017-03-31 23:25:14 +02:00
public void update() {
gameRulesImmutable().forEach((String rule, String val) -> match.getWorld().setGameRuleValue(rule, val));
}
public Map<String, String> gameRules() {
return gameRules;
}
public ImmutableMap<String, String> gameRulesImmutable() {
return ImmutableMap.copyOf(gameRules());
}
2017-01-30 01:43:34 +01:00
}