Add WorldGameRuleChangeEvent

This commit is contained in:
Jake Potrebic
2020-12-20 16:41:44 -08:00
parent e793c7d8be
commit 1e05072232
3 changed files with 59 additions and 14 deletions

View File

@@ -1884,9 +1884,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
if (rule == null || value == null) return false;
if (!this.isGameRule(rule)) return false;
// Paper start - Add WorldGameRuleChangeEvent
GameRule<?> gameRule = GameRule.getByName(rule);
io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(this, null, gameRule, value);
if (!event.callEvent()) return false;
// Paper end - Add WorldGameRuleChangeEvent
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(this.getGameRulesNMS().get(rule));
handle.deserialize(value);
handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
handle.onChanged(this.getHandle());
return true;
}
@@ -1921,9 +1926,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
Preconditions.checkArgument(newValue != null, "GameRule value cannot be null");
if (!this.isGameRule(rule.getName())) return false;
// Paper start - Add WorldGameRuleChangeEvent
io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(this, null, rule, String.valueOf(newValue));
if (!event.callEvent()) return false;
// Paper end - Add WorldGameRuleChangeEvent
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(this.getGameRulesNMS().get(rule.getName()));
handle.deserialize(newValue.toString());
handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
handle.onChanged(this.getHandle());
return true;
}