mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add WorldGameRuleChangeEvent
This commit is contained in:
parent
e793c7d8be
commit
1e05072232
3 changed files with 59 additions and 14 deletions
|
@ -1,14 +1,17 @@
|
|||
--- a/net/minecraft/server/commands/GameRuleCommand.java
|
||||
+++ b/net/minecraft/server/commands/GameRuleCommand.java
|
||||
@@ -34,7 +34,7 @@
|
||||
@@ -34,9 +34,9 @@
|
||||
|
||||
static <T extends GameRules.Value<T>> int setRule(CommandContext<CommandSourceStack> context, GameRules.Key<T> key) {
|
||||
CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
|
||||
- T t0 = commandlistenerwrapper.getServer().getGameRules().getRule(key);
|
||||
+ T t0 = commandlistenerwrapper.getLevel().getGameRules().getRule(key); // CraftBukkit
|
||||
|
||||
t0.setFromArgument(context, "value");
|
||||
- t0.setFromArgument(context, "value");
|
||||
+ t0.setFromArgument(context, "value", key); // Paper - Add WorldGameRuleChangeEvent
|
||||
commandlistenerwrapper.sendSuccess(() -> {
|
||||
return Component.translatable("commands.gamerule.set", key.getId(), t0.toString());
|
||||
}, true);
|
||||
@@ -44,7 +44,7 @@
|
||||
}
|
||||
|
||||
|
|
|
@ -108,11 +108,18 @@
|
|||
}
|
||||
|
||||
public void callVisitor(GameRules.GameRuleTypeVisitor consumer, GameRules.Key<T> key) {
|
||||
@@ -326,17 +326,17 @@
|
||||
@@ -322,21 +322,21 @@
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
||||
this.updateFromArgument(context, name);
|
||||
- protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name);
|
||||
+ protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey); // Paper - Add WorldGameRuleChangeEvent
|
||||
|
||||
- public void setFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
||||
- this.updateFromArgument(context, name);
|
||||
- this.onChanged(((CommandSourceStack) context.getSource()).getServer());
|
||||
+ public void setFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey) { // Paper - Add WorldGameRuleChangeEvent
|
||||
+ this.updateFromArgument(context, name, gameRuleKey); // Paper - Add WorldGameRuleChangeEvent
|
||||
+ this.onChanged(((CommandSourceStack) context.getSource()).getLevel()); // CraftBukkit - per-world
|
||||
}
|
||||
|
||||
|
@ -149,7 +156,20 @@
|
|||
return new GameRules.Type<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> {
|
||||
return new GameRules.BooleanValue(gamerules_gameruledefinition, initialValue);
|
||||
}, changeCallback, GameRules.GameRuleTypeVisitor::visitBoolean, FeatureFlagSet.of());
|
||||
@@ -391,9 +391,9 @@
|
||||
@@ -383,17 +383,20 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
||||
- this.value = BoolArgumentType.getBool(context, name);
|
||||
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<BooleanValue> gameRuleKey) { // Paper start - Add WorldGameRuleChangeEvent
|
||||
+ io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(context.getSource().getBukkitWorld(), context.getSource().getBukkitSender(), (org.bukkit.GameRule<Boolean>) org.bukkit.GameRule.getByName(gameRuleKey.toString()), String.valueOf(BoolArgumentType.getBool(context, name)));
|
||||
+ if (!event.callEvent()) return;
|
||||
+ this.value = Boolean.parseBoolean(event.getValue());
|
||||
+ // Paper end - Add WorldGameRuleChangeEvent
|
||||
}
|
||||
|
||||
public boolean get() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
|
@ -162,7 +182,7 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -402,7 +402,7 @@
|
||||
@@ -402,7 +405,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -171,7 +191,7 @@
|
|||
this.value = Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
@@ -421,9 +421,9 @@
|
||||
@@ -421,9 +424,9 @@
|
||||
return new GameRules.BooleanValue(this.type, this.value);
|
||||
}
|
||||
|
||||
|
@ -184,7 +204,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -431,13 +431,13 @@
|
||||
@@ -431,13 +434,13 @@
|
||||
|
||||
private int value;
|
||||
|
||||
|
@ -200,7 +220,20 @@
|
|||
return new GameRules.Type<>(() -> {
|
||||
return IntegerArgumentType.integer(min, max);
|
||||
}, (gamerules_gameruledefinition) -> {
|
||||
@@ -464,9 +464,9 @@
|
||||
@@ -456,17 +459,20 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
- protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
||||
- this.value = IntegerArgumentType.getInteger(context, name);
|
||||
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<IntegerValue> gameRuleKey) { // Paper start - Add WorldGameRuleChangeEvent
|
||||
+ io.papermc.paper.event.world.WorldGameRuleChangeEvent event = new io.papermc.paper.event.world.WorldGameRuleChangeEvent(context.getSource().getBukkitWorld(), context.getSource().getBukkitSender(), (org.bukkit.GameRule<Integer>) org.bukkit.GameRule.getByName(gameRuleKey.toString()), String.valueOf(IntegerArgumentType.getInteger(context, name)));
|
||||
+ if (!event.callEvent()) return;
|
||||
+ this.value = Integer.parseInt(event.getValue());
|
||||
+ // Paper end - Add WorldGameRuleChangeEvent
|
||||
}
|
||||
|
||||
public int get() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
|
@ -213,7 +246,7 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -475,7 +475,7 @@
|
||||
@@ -475,7 +481,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -222,7 +255,7 @@
|
|||
this.value = IntegerValue.safeParse(value);
|
||||
}
|
||||
|
||||
@@ -517,9 +517,9 @@
|
||||
@@ -517,9 +523,9 @@
|
||||
return new GameRules.IntegerValue(this.type, this.value);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue