mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-14 06:36:33 +01:00
0cdce89d59
If a playerdata doesn't contain a valid, loaded world, reset to the main world spawn point
99 lines
5.8 KiB
Diff
99 lines
5.8 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] Added 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..307854468ac985560b4c63b6e9897c444a7b8a3a 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
|
|
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 6a1001cb708a7f779a801428d2b00fbcde888bc1..2e240ad721928a9a68370114ba61c21884ef1472 100644
|
|
--- a/src/main/java/net/minecraft/world/level/GameRules.java
|
|
+++ b/src/main/java/net/minecraft/world/level/GameRules.java
|
|
@@ -281,10 +281,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
|
|
|
|
- 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
|
|
+ this.updateFromArgument(context, name, gameRuleKey); // Paper
|
|
this.onChanged(((CommandSourceStack) context.getSource()).getServer());
|
|
}
|
|
|
|
@@ -342,8 +342,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
|
|
+ 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
|
|
}
|
|
|
|
public boolean get() {
|
|
@@ -407,8 +410,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
|
|
+ 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
|
|
}
|
|
|
|
public int get() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 56710af63bf432ab38c3a39ad3b734371bb429d7..9b4276290c99cbf9f618746d49746ee9b074744a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -1846,8 +1846,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
if (!this.isGameRule(rule)) return false;
|
|
|
|
+ // Paper start
|
|
+ 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
|
|
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule));
|
|
- handle.deserialize(value);
|
|
+ handle.deserialize(event.getValue()); // Paper
|
|
handle.onChanged(this.getHandle().getServer());
|
|
return true;
|
|
}
|
|
@@ -1883,8 +1888,12 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
|
|
if (!this.isGameRule(rule.getName())) return false;
|
|
|
|
+ // Paper start
|
|
+ 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
|
|
GameRules.Value<?> handle = this.getHandle().getGameRules().getRule(CraftWorld.getGameRulesNMS().get(rule.getName()));
|
|
- handle.deserialize(newValue.toString());
|
|
+ handle.deserialize(event.getValue()); // Paper
|
|
handle.onChanged(this.getHandle().getServer());
|
|
return true;
|
|
}
|