diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java index 7c35bcc6..046e884d 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -1,10 +1,13 @@ package org.bukkit; +import java.util.List; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import org.bukkit.entity.Entity; import org.bukkit.entity.ItemDrop; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.PoweredMinecart; import org.bukkit.entity.Minecart; import org.bukkit.entity.StorageMinecart; @@ -155,6 +158,20 @@ public interface World { * @return */ public Boat spawnBoat(Location loc); + + /** + * Get a list of all entities. + * + * @return + */ + public List getEntities(); + + /** + * Get a list of all living entities. + * + * @return + */ + public List getLivingEntities(); /** * Gets the name of this world. This is not guaranteed to be unique. @@ -171,6 +188,7 @@ public interface World { * @return Id of this world */ public long getId(); + /** * Gets the default spawn location. */ diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java index cb4ba7dc..457530c6 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java @@ -187,4 +187,18 @@ public interface Block { * @return Biome type containing this block */ Biome getBiome(); + + /** + * Returns true if the block is being powered by Redstone. + * + * @return + */ + boolean isBlockPowered(); + + /** + * Returns true if the block is being indirectly powered by Redstone. + * + * @return + */ + boolean isBlockIndirectlyPowered(); } diff --git a/src/main/java/org/bukkit/command/CommandMap.java b/src/main/java/org/bukkit/command/CommandMap.java index 9d8c2dea..884fea2d 100644 --- a/src/main/java/org/bukkit/command/CommandMap.java +++ b/src/main/java/org/bukkit/command/CommandMap.java @@ -26,4 +26,8 @@ public interface CommandMap { */ public boolean dispatch(CommandSender sender, String cmdLine); + /** + * Clears all registered commands. + */ + public void clearCommands(); } diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java index 21b681b3..73198f8f 100644 --- a/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -14,24 +14,16 @@ import org.bukkit.plugin.PluginDescriptionFile; public final class SimpleCommandMap implements CommandMap { private final Map knownCommands = new HashMap(); + private final Server server; public SimpleCommandMap(final Server server) { + this.server = server; + setDefaultCommands(server); + } + + private void setDefaultCommands(final Server server) { register("bukkit", new VersionCommand("version", server)); - - register("reload", "bukkit", new Command("reload") { - @Override - public boolean execute(CommandSender sender, String currentAlias, String[] args) { - if (sender.isOp()) { - server.reload(); - sender.sendMessage(ChatColor.GREEN + "Reload complete."); - } else { - sender.sendMessage(ChatColor.RED + "You do not have sufficient access" - + " to reload this server."); - } - - return true; - } - }); + register("bukkit", new ReloadCommand("reload", server)); } /** @@ -86,6 +78,13 @@ public final class SimpleCommandMap implements CommandMap { return isRegisteredCommand; } + public void clearCommands() { + synchronized (this) { + knownCommands.clear(); + setDefaultCommands(server); + } + } + private static class VersionCommand extends Command { private final Server server; @@ -183,4 +182,28 @@ public final class SimpleCommandMap implements CommandMap { return result.toString(); } } + + private static class ReloadCommand extends Command { + + private final Server server; + + public ReloadCommand(String name, Server server) { + super(name); + this.server = server; + this.tooltip = "Reloads the server configuration and plugins"; + this.usageMessage = "/reload"; + this.setAliases(Arrays.asList("rl")); + } + + @Override + public boolean execute(Player player, String currentAlias, String[] args) { + if (player.isOp()) { + server.reload(); + player.sendMessage(ChatColor.GREEN + "Reload complete."); + } else { + player.sendMessage(ChatColor.RED + "You do not have sufficient access" + " to reload this server."); + } + return true; + } + } } \ No newline at end of file diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java index 96d97c78..c439ebec 100644 --- a/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java @@ -56,4 +56,12 @@ public interface Player extends HumanEntity, CommandSender { * @return */ public void kickPlayer(String message); + + /** + * Makes the player perform the given command + * + * @param command Command to perform + * @return true if the command was successful, otherwise false + */ + public boolean performCommand(String command); } diff --git a/src/main/java/org/bukkit/event/block/BlockBurnEvent.java b/src/main/java/org/bukkit/event/block/BlockBurnEvent.java new file mode 100644 index 00000000..ba8b64ff --- /dev/null +++ b/src/main/java/org/bukkit/event/block/BlockBurnEvent.java @@ -0,0 +1,31 @@ + + +package org.bukkit.event.block; + +import org.bukkit.block.Block; +import org.bukkit.event.Cancellable; + +/** + * Called when a block is destroyed because of being burnt by fire + * @author tkelly + */ +public class BlockBurnEvent extends BlockEvent implements Cancellable { + private boolean cancelled; + + public BlockBurnEvent(Block block) { + super(Type.BLOCK_BURN, block); + this.cancelled = false; + } + + public boolean isCancelled() { + return cancelled; + } + + /** + * Allow for the block to be stopped from being destroyed + * @param cancel + */ + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java b/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java new file mode 100644 index 00000000..a18d93e5 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java @@ -0,0 +1,36 @@ + +package org.bukkit.event.entity; + +import java.util.List; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; + +/** + * Thrown whenever a LivingEntity dies + */ +public class EntityDeathEvent extends EntityEvent { + private List drops; + + public EntityDeathEvent(final Type type, final Entity what, final List drops) { + super(type, what); + this.drops = drops; + } + + /** + * Sets what items will be dropped when this entity dies + * + * @param drops Items to drop when the entity dies + */ + public void setDrops(final List drops) { + this.drops = drops; + } + + /** + * Gets all the items which will drop when the entity dies + * + * @return Items to drop when the entity dies + */ + public List getDrops() { + return drops; + } +} diff --git a/src/main/java/org/bukkit/event/entity/EntityTargetEvent.java b/src/main/java/org/bukkit/event/entity/EntityTargetEvent.java new file mode 100644 index 00000000..d291b337 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityTargetEvent.java @@ -0,0 +1,99 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; + +/** + * This event is fired when a mob (or any creature) targets another entity + * @author tkelly + */ +public class EntityTargetEvent extends EntityEvent implements Cancellable { + private boolean cancel; + private Entity target; + private TargetReason reason; + + public EntityTargetEvent(Entity entity, Entity target, TargetReason reason) { + super(Type.ENTITY_TARGET, entity); + this.target = target; + this.cancel = false; + this.reason = reason; + } + + public boolean isCancelled() { + return cancel; + } + + /** + * Cancel the change in target. The entity will remain with their original + * target, whether that is nothing or another entity. + * @param cancel + */ + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Returns the reason for the targeting + */ + public TargetReason getReason() { + return reason; + } + + /** + * Get the entity that this is target. + * This is possible to be null in the case that the event is called when + * the mob forgets its target. + */ + public Entity getTarget() { + return target; + } + + /** + * Set the entity that you want the mob to target instead. + * It is possible to be null, null will cause the entity to be + * target-less. + * + * This is different from cancelling the event. Cancelling the event + * will cause the entity to keep an original target, while setting to be + * null will cause the entity to be reset + * + * @param target The entity to target + */ + public void setTarget(Entity target) { + this.target = target; + } + + /** + * An enum to specify the reason for the targeting + */ + public enum TargetReason + { + /** + * When the entity's target has died, and so it no longer targets it + */ + TARGET_DIED, + /** + * When the entity doesn't have a target, so it attacks the nearest + * player + */ + CLOSEST_PLAYER, + /** + * When the target attacks the entity, so entity targets it + */ + TARGET_ATTACKED_ENTITY, + /** + * When the target attacks a fellow pig zombie, so the whole group + * will target him with this reason. + */ + PIG_ZOMBIE_TARGET, + /** + * When the target is forgotten for whatever reason. + * Currently only occurs in with spiders when there is a high brightness + */ + FORGOT_TARGET, + /** + * For custom calls to the event + */ + CUSTOM + } +} diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java index df86ec6c..c978e1e1 100644 --- a/src/main/java/org/bukkit/plugin/PluginManager.java +++ b/src/main/java/org/bukkit/plugin/PluginManager.java @@ -75,6 +75,16 @@ public interface PluginManager { */ public Plugin[] loadPlugins(File directory); + /** + * Disables all the loaded plugins + */ + public void disablePlugins(); + + /** + * Disables and removes all plugins + */ + public void clearPlugins(); + /** * Calls a player related event with the given details * diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index e93b07a5..877b3548 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -176,12 +176,27 @@ public final class SimplePluginManager implements PluginManager { } } + public void disablePlugins() { + for(Plugin plugin: getPlugins()) { + disablePlugin(plugin); + } + } + public void disablePlugin(final Plugin plugin) { if (plugin.isEnabled()) { plugin.getPluginLoader().disablePlugin(plugin); } } + public void clearPlugins() { + synchronized (this) { + disablePlugins(); + plugins.clear(); + lookupNames.clear(); + listeners.clear(); + } + } + /** * Calls a player related event with the given details * diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index cf08ccbd..77ae3191 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -8,6 +8,7 @@ import java.lang.reflect.Constructor; import java.net.URL; import java.util.HashMap; import java.util.Map; +import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.regex.Pattern; @@ -366,10 +367,20 @@ public final class JavaPluginLoader implements PluginLoader { if (plugin.isEnabled()) { JavaPlugin jPlugin = (JavaPlugin)plugin; + ClassLoader cloader = jPlugin.getClassLoader(); server.getPluginManager().callEvent(new PluginEvent(Event.Type.PLUGIN_DISABLE, plugin)); jPlugin.setEnabled(false); + + if (cloader instanceof PluginClassLoader) { + PluginClassLoader loader = (PluginClassLoader)cloader; + Set names = loader.getClasses(); + + for (String name : names) { + classes.remove(name); + } + } } } } diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java index 0dbaf4eb..d17e0f4f 100644 --- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java +++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java @@ -4,6 +4,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** * A ClassLoader for plugins, to allow shared classes across multiple plugins @@ -38,4 +39,8 @@ public class PluginClassLoader extends URLClassLoader { return result; } + + public Set getClasses() { + return classes.keySet(); + } }