2021-06-14 20:50:22 +02:00
|
|
|
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
|
2024-01-19 22:13:42 +01:00
|
|
|
Subject: [PATCH] Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
2024-10-23 17:58:11 +02:00
|
|
|
index 6fc70f07f9ba964ff6f5176367dab788decfc917..da0600ab3b0a983ac36cb777d21160bdaced7c52 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
2024-10-23 17:58:11 +02:00
|
|
|
@@ -36,7 +36,7 @@ public class GameRuleCommand {
|
2021-06-14 20:50:22 +02:00
|
|
|
CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
|
|
|
|
T t0 = commandlistenerwrapper.getLevel().getGameRules().getRule(key); // CraftBukkit
|
|
|
|
|
|
|
|
- t0.setFromArgument(context, "value");
|
2024-01-19 22:13:42 +01:00
|
|
|
+ t0.setFromArgument(context, "value", key); // Paper - Add WorldGameRuleChangeEvent
|
2023-06-08 01:56:33 +02:00
|
|
|
commandlistenerwrapper.sendSuccess(() -> {
|
|
|
|
return Component.translatable("commands.gamerule.set", key.getId(), t0.toString());
|
|
|
|
}, true);
|
2021-06-14 20:50:22 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/GameRules.java b/src/main/java/net/minecraft/world/level/GameRules.java
|
2024-10-23 17:58:11 +02:00
|
|
|
index 7ea92a0b0f5d4eb6bd873e61c42bc0499d5d2028..09299e45552eb998fd02123c3921c0653f85083d 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/GameRules.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
|
2024-10-23 17:58:11 +02:00
|
|
|
@@ -322,10 +322,10 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
- protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ protected abstract void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey); // Paper - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
- public void setFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.updateFromArgument(context, name);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ public void setFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<T> gameRuleKey) { // Paper - Add WorldGameRuleChangeEvent
|
|
|
|
+ this.updateFromArgument(context, name, gameRuleKey); // Paper - Add WorldGameRuleChangeEvent
|
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
|
|
|
this.onChanged(((CommandSourceStack) context.getSource()).getLevel()); // CraftBukkit - per-world
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
2024-10-23 17:58:11 +02:00
|
|
|
@@ -383,8 +383,11 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
- protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.value = BoolArgumentType.getBool(context, name);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<BooleanValue> gameRuleKey) { // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean get() {
|
2024-10-23 17:58:11 +02:00
|
|
|
@@ -456,8 +459,11 @@ public class GameRules {
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
- protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name) {
|
|
|
|
- this.value = IntegerArgumentType.getInteger(context, name);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ protected void updateFromArgument(CommandContext<CommandSourceStack> context, String name, GameRules.Key<IntegerValue> gameRuleKey) { // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int get() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
Rework async chunk api implementation
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.
2024-11-19 07:34:32 +01:00
|
|
|
index 2ad9c104c7a99882417f9662d657841636751223..5304fb017b6ecda3ff96e1e44be444260fd8d715 100644
|
2021-06-14 20:50:22 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
Rework async chunk api implementation
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.
2024-11-19 07:34:32 +01:00
|
|
|
@@ -1879,9 +1879,14 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2024-10-23 17:58:11 +02:00
|
|
|
if (rule == null || value == null) return false;
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
if (!this.isGameRule(rule)) return false;
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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;
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2024-10-23 17:58:11 +02:00
|
|
|
|
|
|
|
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(this.getGameRulesNMS().get(rule));
|
2021-06-14 20:50:22 +02:00
|
|
|
- handle.deserialize(value);
|
2024-01-19 22:13:42 +01:00
|
|
|
+ handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
|
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
|
|
|
handle.onChanged(this.getHandle());
|
2021-06-14 20:50:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
Rework async chunk api implementation
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.
2024-11-19 07:34:32 +01:00
|
|
|
@@ -1916,9 +1921,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
2024-10-23 17:58:11 +02:00
|
|
|
Preconditions.checkArgument(newValue != null, "GameRule value cannot be null");
|
2021-06-14 20:50:22 +02:00
|
|
|
|
|
|
|
if (!this.isGameRule(rule.getName())) return false;
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper start - Add WorldGameRuleChangeEvent
|
2021-06-14 20:50:22 +02:00
|
|
|
+ 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;
|
2024-01-19 22:13:42 +01:00
|
|
|
+ // Paper end - Add WorldGameRuleChangeEvent
|
2024-10-23 17:58:11 +02:00
|
|
|
|
|
|
|
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(this.getGameRulesNMS().get(rule.getName()));
|
2021-06-14 20:50:22 +02:00
|
|
|
- handle.deserialize(newValue.toString());
|
2024-01-19 22:13:42 +01:00
|
|
|
+ handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
|
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
|
|
|
handle.onChanged(this.getHandle());
|
2021-06-14 20:50:22 +02:00
|
|
|
return true;
|
|
|
|
}
|