mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 04:56:29 +00:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
101 lines
6.4 KiB
Diff
101 lines
6.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sun, 20 Dec 2020 16:41:44 -0800
|
|
Subject: [PATCH] Add WorldGameRuleChangeEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
|
index 6fc70f07f9ba964ff6f5176367dab788decfc917..da0600ab3b0a983ac36cb777d21160bdaced7c52 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
|
@@ -36,7 +36,7 @@ public class GameRuleCommand {
|
|
CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
|
|
T t0 = commandlistenerwrapper.getLevel().getGameRules().getRule(key); // CraftBukkit
|
|
|
|
- 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);
|
|
diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java
|
|
index 7ea92a0b0f5d4eb6bd873e61c42bc0499d5d2028..09299e45552eb998fd02123c3921c0653f85083d 100644
|
|
--- a/src/main/java/net/minecraft/world/level/GameRules.java
|
|
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
|
|
@@ -322,10 +322,10 @@ public class GameRules {
|
|
this.type = type;
|
|
}
|
|
|
|
- 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);
|
|
+ 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
|
|
}
|
|
|
|
@@ -383,8 +383,11 @@ public class GameRules {
|
|
}
|
|
|
|
@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() {
|
|
@@ -456,8 +459,11 @@ public class GameRules {
|
|
}
|
|
|
|
@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() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 2ad9c104c7a99882417f9662d657841636751223..5304fb017b6ecda3ff96e1e44be444260fd8d715 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -1879,9 +1879,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;
|
|
}
|
|
@@ -1916,9 +1921,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;
|
|
}
|