From c07e32c1de57898d5f7ad2fbfa0800d65fc20f5a Mon Sep 17 00:00:00 2001 From: Taylor Kelly Date: Wed, 26 Jan 2011 14:26:24 -0500 Subject: [PATCH 01/10] EntityTargetEvent --- .../net/minecraft/server/EntityCreature.java | 32 +++++++++++++++++-- .../java/net/minecraft/server/EntityMobs.java | 20 +++++++++++- .../net/minecraft/server/EntityPigZombie.java | 24 ++++++++++++-- .../net/minecraft/server/EntitySpider.java | 18 +++++++++-- 4 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityCreature.java b/src/main/java/net/minecraft/server/EntityCreature.java index 801b64ad7d..98afd9cdc7 100644 --- a/src/main/java/net/minecraft/server/EntityCreature.java +++ b/src/main/java/net/minecraft/server/EntityCreature.java @@ -5,6 +5,9 @@ import java.util.Random; // CraftBukkit start import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.entity.CraftCreature; +import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; // CraftBukkit end public class EntityCreature extends EntityLiving { @@ -27,12 +30,37 @@ public class EntityCreature extends EntityLiving { float f = 16F; if (d == null) { - d = l(); + // CraftBukkit start + Entity target = l(); + if(target != null) { + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), TargetReason.CLOSEST_PLAYER); + CraftServer server = ((WorldServer) this.l).getServer(); + server.getPluginManager().callEvent(event); + if(!event.isCancelled()) { + if(event.getTarget() == null) { + d = null; + } else { + d = ((CraftEntity) event.getTarget()).getHandle(); + } + } + } + // CraftBukkit end if (d != null) { a = l.a(((Entity) (this)), d, f); } } else if (!d.B()) { - d = null; + // CraftBukkit start + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, TargetReason.TARGET_DIED); + CraftServer server = ((WorldServer) this.l).getServer(); + server.getPluginManager().callEvent(event); + if(!event.isCancelled()) { + if(event.getTarget() == null) { + d = null; + } else { + d = ((CraftEntity) event.getTarget()).getHandle(); + } + } + // CraftBukkit end } else { float f1 = d.a(((Entity) (this))); diff --git a/src/main/java/net/minecraft/server/EntityMobs.java b/src/main/java/net/minecraft/server/EntityMobs.java index df910e41d5..e75b345c3d 100644 --- a/src/main/java/net/minecraft/server/EntityMobs.java +++ b/src/main/java/net/minecraft/server/EntityMobs.java @@ -5,10 +5,13 @@ import java.util.Random; // CraftBukkit start import org.bukkit.craftbukkit.entity.CraftMonster; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; // CraftBukkit end public class EntityMobs extends EntityCreature implements IMobs { @@ -57,7 +60,22 @@ public class EntityMobs extends EntityCreature implements IMobs { return true; } if (entity != this) { - d = entity; + // CraftBukkit start + org.bukkit.entity.Entity bukkitTarget = null; + if(entity != null) { + bukkitTarget = entity.getBukkitEntity(); + } + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, TargetReason.TARGET_ATTACKED_ENTITY); + CraftServer server = ((WorldServer) this.l).getServer(); + server.getPluginManager().callEvent(event); + if(!event.isCancelled()) { + if(event.getTarget() == null) { + d = null; + } else { + d = ((CraftEntity) event.getTarget()).getHandle(); + } + } + // CraftBukkit end } return true; } else { diff --git a/src/main/java/net/minecraft/server/EntityPigZombie.java b/src/main/java/net/minecraft/server/EntityPigZombie.java index f22ea2f04f..18e768ec33 100644 --- a/src/main/java/net/minecraft/server/EntityPigZombie.java +++ b/src/main/java/net/minecraft/server/EntityPigZombie.java @@ -5,7 +5,10 @@ import java.util.Random; // CraftBukkit start import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftPigZombie; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; // CraftBukkit end public class EntityPigZombie extends EntityZombie { @@ -82,9 +85,24 @@ public class EntityPigZombie extends EntityZombie { } private void g(Entity entity) { - d = entity; - a = 400 + W.nextInt(400); - b = W.nextInt(40); + // CraftBukkit start + org.bukkit.entity.Entity bukkitTarget = null; + if(entity != null) { + bukkitTarget = entity.getBukkitEntity(); + } + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), bukkitTarget, TargetReason.PIG_ZOMBIE_TARGET); + CraftServer server = ((WorldServer) this.l).getServer(); + server.getPluginManager().callEvent(event); + if(!event.isCancelled()) { + if(event.getTarget() == null) { + d = null; + } else { + d = ((CraftEntity) event.getTarget()).getHandle(); + a = 400 + W.nextInt(400); + b = W.nextInt(40); + } + } + // CraftBukkit end } protected String e() { diff --git a/src/main/java/net/minecraft/server/EntitySpider.java b/src/main/java/net/minecraft/server/EntitySpider.java index 1d1c746c01..77bd7eb4d3 100644 --- a/src/main/java/net/minecraft/server/EntitySpider.java +++ b/src/main/java/net/minecraft/server/EntitySpider.java @@ -4,7 +4,10 @@ import java.util.Random; // CraftBukkit start import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftSpider; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent.TargetReason; // CraftBukkit stop public class EntitySpider extends EntityMobs { @@ -52,8 +55,19 @@ public class EntitySpider extends EntityMobs { float f2 = b(1.0F); if (f2 > 0.5F && W.nextInt(100) == 0) { - this.d = null; - return; + // CraftBukkit start + EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, TargetReason.FORGOT_TARGET); + CraftServer server = ((WorldServer) this.l).getServer(); + server.getPluginManager().callEvent(event); + if(!event.isCancelled()) { + if(event.getTarget() == null) { + this.d = null; + } else { + this.d = ((CraftEntity) event.getTarget()).getHandle(); + } + return; + } + // CraftBukkit end } if (f1 > 2.0F && f1 < 6F && W.nextInt(10) == 0) { if (A) { From 7a898bdba8257a5f98ebdae99fa38b4429ca5828 Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 26 Jan 2011 12:03:54 -0800 Subject: [PATCH 02/10] Added methods to get a list of entities to World. This replies on net.minecraft.server.Entity.bukkitEntity not being null (otherwise it won't be returned). --- .../org/bukkit/craftbukkit/CraftWorld.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index e4989c4e8a..ce456411aa 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -3,8 +3,11 @@ package org.bukkit.craftbukkit; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.entity.*; import org.bukkit.entity.*; +import org.bukkit.entity.Entity; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Random; import net.minecraft.server.*; @@ -316,4 +319,46 @@ public class CraftWorld implements World { return hash; } } + + @Override + public List getEntities() { + List list = new ArrayList(); + + for (Object o : world.b) { + if (o instanceof net.minecraft.server.Entity) { + net.minecraft.server.Entity mcEnt + = (net.minecraft.server.Entity)o; + + Entity bukkitEntity = mcEnt.getBukkitEntity(); + + // Assuming that bukkitEntity isn't null + if (bukkitEntity != null) { + list.add(bukkitEntity); + } + } + } + + return list; + } + + @Override + public List getLivingEntities() { + List list = new ArrayList(); + + for (Object o : world.b) { + if (o instanceof net.minecraft.server.Entity) { + net.minecraft.server.Entity mcEnt + = (net.minecraft.server.Entity)o; + + Entity bukkitEntity = mcEnt.getBukkitEntity(); + + // Assuming that bukkitEntity isn't null + if (bukkitEntity != null && bukkitEntity instanceof LivingEntity) { + list.add((LivingEntity)bukkitEntity); + } + } + } + + return list; + } } From f11e575a7214983278567e8b127b86ac83e7af38 Mon Sep 17 00:00:00 2001 From: Taylor Kelly Date: Wed, 26 Jan 2011 16:13:27 -0500 Subject: [PATCH 03/10] BlockBurnEvent --- .../java/net/minecraft/server/BlockFire.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/minecraft/server/BlockFire.java b/src/main/java/net/minecraft/server/BlockFire.java index d3c8e39639..c1b6279df0 100644 --- a/src/main/java/net/minecraft/server/BlockFire.java +++ b/src/main/java/net/minecraft/server/BlockFire.java @@ -7,6 +7,7 @@ import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.craftbukkit.CraftWorld; import java.util.Random; +import org.bukkit.event.block.BlockBurnEvent; // CraftBukkit end public class BlockFire extends Block { @@ -116,31 +117,36 @@ public class BlockFire extends Block { if (random.nextInt(l) < i1) { boolean flag = world.a(i, j, k) == Block.am.bi; + // CraftBukkit start: BlockBurnEvent + Server server = ((WorldServer)world).getServer(); + CraftWorld cworld = ((WorldServer)world).getWorld(); + org.bukkit.block.Block theBlock = (cworld.getBlockAt(i, j, k)); + BlockBurnEvent burnEvent = new BlockBurnEvent(theBlock); + server.getPluginManager().callEvent(burnEvent); + if(!burnEvent.isCancelled()) { + if (random.nextInt(2) == 0) { + // CraftBukkit start: Call to stop very slow spread of fire. - if (random.nextInt(2) == 0) { - // CraftBukkit start: Call to stop very slow spread of fire. - Server server = ((WorldServer)world).getServer(); - CraftWorld cworld = ((WorldServer)world).getWorld(); - - org.bukkit.block.Block theBlock = (cworld.getBlockAt(i, j, k)); - IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SLOW_SPREAD; - Player thePlayer = null; - - if (theBlock.getTypeId() != Block.ar.bi){ - BlockIgniteEvent event = new BlockIgniteEvent(theBlock, igniteCause, thePlayer); - server.getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; + IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SLOW_SPREAD; + Player thePlayer = null; + + if (theBlock.getTypeId() != Block.ar.bi){ + BlockIgniteEvent event = new BlockIgniteEvent(theBlock, igniteCause, thePlayer); + server.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } } + // CraftBukkit end + world.e(i, j, k, bi); + } else { + world.e(i, j, k, 0); + } + if (flag) { + Block.am.a(world, i, j, k, 0); } - // CraftBukkit end - world.e(i, j, k, bi); - } else { - world.e(i, j, k, 0); - } - if (flag) { - Block.am.a(world, i, j, k, 0); } + // CraftBukkit end: BlockBurnEvent } } From 105a14d6d13a61881a20cd9e5baa4b7b8e4dd15f Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Thu, 27 Jan 2011 13:26:37 +0000 Subject: [PATCH 04/10] You don't override for interfaces! --- src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index ce456411aa..cdeffc3a7a 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -320,7 +320,6 @@ public class CraftWorld implements World { } } - @Override public List getEntities() { List list = new ArrayList(); @@ -341,7 +340,6 @@ public class CraftWorld implements World { return list; } - @Override public List getLivingEntities() { List list = new ArrayList(); From cab61f169e16e5871f5b2c6bf7d729b221fe37f7 Mon Sep 17 00:00:00 2001 From: Taylor Kelly Date: Thu, 27 Jan 2011 16:15:41 -0500 Subject: [PATCH 05/10] onDisable on stop - stephank --- src/main/java/net/minecraft/server/MinecraftServer.java | 4 ++++ src/main/java/org/bukkit/craftbukkit/CraftServer.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 1011b9a78a..56755c1745 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -160,6 +160,10 @@ public class MinecraftServer implements ICommandListener, Runnable { private void g() { a.info("Stopping server"); + if(server != null) { + server.disablePlugins(); + } + if (f != null) { f.d(); } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 68c9eb593a..8368d377f7 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -52,6 +52,10 @@ public final class CraftServer implements Server { } } + public void disablePlugins() { + pluginManager.disablePlugins(); + } + private void loadPlugin(Plugin plugin) { List pluginCommands = PluginCommandYamlParser.parse(plugin); if (!pluginCommands.isEmpty()) { From c2d9af58fec008b2651dd7564421f0c65e549b7f Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 28 Jan 2011 09:15:32 +0000 Subject: [PATCH 06/10] Implemented player.performCommand(String) --- src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index a1ed1165ed..2ceb8d9781 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -106,4 +106,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { entity.a.b(((Packet) (new Packet6SpawnPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())))); } + public boolean performCommand(String command) { + return server.dispatchCommand(this, command); + } } From b6b5a1ef77792eb6f5d83e30a3e2c2a4435bdcbc Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 28 Jan 2011 14:18:49 +0000 Subject: [PATCH 07/10] server.reload() now reloads plugins --- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 8368d377f7..250e0ff2e8 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -175,5 +175,9 @@ public final class CraftServer implements Server { console.e.k = monsters ? 1 : 0; console.e.a(monsters, animals); + + pluginManager.clearPlugins(); + commandMap.clearCommands(); + loadPlugins(); } } From 61c37bd3696329ef2ea42d4578f8694b95ef5792 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 28 Jan 2011 10:24:53 -0800 Subject: [PATCH 08/10] Added Block.isBlockPowered(), block.isBlockIndirectlyPowered(). --- .../java/org/bukkit/craftbukkit/block/CraftBlock.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 4c00089685..4d19e34b6b 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -337,6 +337,14 @@ public class CraftBlock implements Block { return null; } + public boolean isBlockPowered() { + return world.getHandle().o(x, y, z); + } + + public boolean isBlockIndirectlyPowered() { + return world.getHandle().p(x, y, z); + } + public void update() { type = world.getHandle().a(x, y, z); data = (byte)world.getHandle().b(x, y, z); From 0daa2420da3da00379c86b651bfb08e131b83e53 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 28 Jan 2011 11:39:18 -0800 Subject: [PATCH 09/10] Fixed fire spread hook providing the wrong block. --- src/main/java/net/minecraft/server/BlockFire.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/BlockFire.java b/src/main/java/net/minecraft/server/BlockFire.java index c1b6279df0..f1d9581e68 100644 --- a/src/main/java/net/minecraft/server/BlockFire.java +++ b/src/main/java/net/minecraft/server/BlockFire.java @@ -91,7 +91,7 @@ public class BlockFire extends Block { Server server = ((WorldServer)world).getServer(); CraftWorld cworld = ((WorldServer)world).getWorld(); - org.bukkit.block.Block theBlock = (cworld.getBlockAt(i1, j1, k1)); + org.bukkit.block.Block theBlock = (cworld.getBlockAt(i1, k1, j1)); IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SPREAD; Player thePlayer = null; From 8fdd45ab40ce69fe13f8651d945aff1b242993d4 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 28 Jan 2011 11:39:45 -0800 Subject: [PATCH 10/10] Fixed an issue where fire spread cancellation changed the behavior of natural fire. --- src/main/java/net/minecraft/server/BlockFire.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/BlockFire.java b/src/main/java/net/minecraft/server/BlockFire.java index f1d9581e68..96eb7983f5 100644 --- a/src/main/java/net/minecraft/server/BlockFire.java +++ b/src/main/java/net/minecraft/server/BlockFire.java @@ -99,7 +99,7 @@ public class BlockFire extends Block { BlockIgniteEvent event = new BlockIgniteEvent(theBlock, igniteCause, thePlayer); server.getPluginManager().callEvent(event); if (event.isCancelled()) { - return; + continue; } } // CraftBukkit end