From 9e4e2c62af6b6d12cc6a15cbf117d0a7586372c6 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Tue, 30 Oct 2012 21:24:48 -0500 Subject: [PATCH] Expose API for managing and using GameRules. Adds BUKKIT-2757 --- .../net/minecraft/server/EntityPlayer.java | 29 +++++++++++-------- .../net/minecraft/server/WorldServer.java | 5 ++-- .../org/bukkit/craftbukkit/CraftWorld.java | 22 ++++++++++++++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 923e08133c..2ceeac08a5 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -230,16 +230,19 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } java.util.List loot = new java.util.ArrayList(); + boolean keepInventory = this.world.getGameRules().getBoolean("keepInventory"); - for (int i = 0; i < this.inventory.items.length; ++i) { - if (this.inventory.items[i] != null) { - loot.add(new CraftItemStack(this.inventory.items[i])); + if (!keepInventory) { + for (int i = 0; i < this.inventory.items.length; ++i) { + if (this.inventory.items[i] != null) { + loot.add(new CraftItemStack(this.inventory.items[i])); + } } - } - for (int i = 0; i < this.inventory.armor.length; ++i) { - if (this.inventory.armor[i] != null) { - loot.add(new CraftItemStack(this.inventory.armor[i])); + for (int i = 0; i < this.inventory.armor.length; ++i) { + if (this.inventory.armor[i] != null) { + loot.add(new CraftItemStack(this.inventory.armor[i])); + } } } @@ -252,12 +255,14 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } // CraftBukkit - we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory. - for (int i = 0; i < this.inventory.items.length; ++i) { - this.inventory.items[i] = null; - } + if (!keepInventory) { + for (int i = 0; i < this.inventory.items.length; ++i) { + this.inventory.items[i] = null; + } - for (int i = 0; i < this.inventory.armor.length; ++i) { - this.inventory.armor[i] = null; + for (int i = 0; i < this.inventory.armor.length; ++i) { + this.inventory.armor[i] = null; + } } this.closeInventory(); diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index bb17c7e1cf..f9e246c747 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -767,11 +767,12 @@ public class WorldServer extends World implements org.bukkit.BlockChangeDelegate explosion.b = flag1; explosion.a(); explosion.a(false); + */ + // CraftBukkit end - TODO: Check if explosions are still properly implemented + if (!flag1) { explosion.blocks.clear(); } - */ - // CraftBukkit end - TODO: Check if explosions are still properly implemented Iterator iterator = this.players.iterator(); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 2ca3078d97..5855b5498c 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1197,4 +1197,26 @@ public class CraftWorld implements World { getHandle().makeSound(x, y, z, CraftSound.getSound(sound), volume, pitch); } + + public String getGameRuleValue(String rule) { + return getHandle().getGameRules().get(rule); + } + + public boolean setGameRuleValue(String rule, String value) { + // No null values allowed + if (rule == null || value == null) return false; + + if (!isGameRule(rule)) return false; + + getHandle().getGameRules().set(rule, value); + return true; + } + + public String[] getGameRules() { + return getHandle().getGameRules().b(); + } + + public boolean isGameRule(String rule) { + return getHandle().getGameRules().e(rule); + } }