1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-17 18:47:40 +01:00

merge with head

By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
Bukkit/Spigot 2011-01-29 17:18:32 +00:00
commit c736e00b8c
12 changed files with 289 additions and 15 deletions

View file

@ -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<Entity> getEntities();
/**
* Get a list of all living entities.
*
* @return
*/
public List<LivingEntity> 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.
*/

View file

@ -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();
}

View file

@ -26,4 +26,8 @@ public interface CommandMap {
*/
public boolean dispatch(CommandSender sender, String cmdLine);
/**
* Clears all registered commands.
*/
public void clearCommands();
}

View file

@ -14,24 +14,16 @@ import org.bukkit.plugin.PluginDescriptionFile;
public final class SimpleCommandMap implements CommandMap {
private final Map<String, Command> knownCommands = new HashMap<String, Command>();
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;
}
}
}

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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<ItemStack> drops;
public EntityDeathEvent(final Type type, final Entity what, final List<ItemStack> 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<ItemStack> 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<ItemStack> getDrops() {
return drops;
}
}

View file

@ -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
}
}

View file

@ -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
*

View file

@ -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
*

View file

@ -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<String> names = loader.getClasses();
for (String name : names) {
classes.remove(name);
}
}
}
}
}

View file

@ -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<String> getClasses() {
return classes.keySet();
}
}