Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
c5a10665b8
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
99 Zeilen
6.3 KiB
Diff
99 Zeilen
6.3 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 c8c358531dbc167e249bac2af246c5e34fbdd4df..10c1790226e25da3b9b599c9a40de57d5727ddc4 100644
|
|
--- a/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
|
+++ b/src/main/java/net/minecraft/server/commands/GameRuleCommand.java
|
|
@@ -33,7 +33,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 0b46ad360be919e4aeb0ffc0eebae9fe712fb861..51e560d7856f230c5aa2dc32706c3a4996720aa5 100644
|
|
--- a/src/main/java/net/minecraft/world/level/GameRules.java
|
|
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
|
|
@@ -293,10 +293,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
|
|
}
|
|
|
|
@@ -354,8 +354,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() {
|
|
@@ -427,8 +430,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 5ae307f9343ffea39c286992459a6c8069d9fb86..08124dd65d1f950bdec8fcb55d2553c601b30a66 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -1885,8 +1885,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
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(CraftWorld.getGameRulesNMS().get(rule));
|
|
- handle.deserialize(value);
|
|
+ handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
|
|
handle.onChanged(this.getHandle());
|
|
return true;
|
|
}
|
|
@@ -1922,8 +1927,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
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(CraftWorld.getGameRulesNMS().get(rule.getName()));
|
|
- handle.deserialize(newValue.toString());
|
|
+ handle.deserialize(event.getValue()); // Paper - Add WorldGameRuleChangeEvent
|
|
handle.onChanged(this.getHandle());
|
|
return true;
|
|
}
|