Updated events to choose the best platform for certain tasks.

This commit is contained in:
sk89q
2014-06-27 13:14:44 -07:00
parent e52ca6661f
commit 9bb70ad335
14 changed files with 282 additions and 40 deletions

View File

@ -29,8 +29,7 @@ public class BukkitCommandSender extends LocalPlayer {
private CommandSender sender;
private WorldEditPlugin plugin;
public BukkitCommandSender(WorldEditPlugin plugin, ServerInterface server, CommandSender sender) {
super(server);
public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) {
this.plugin = plugin;
this.sender = sender;
}

View File

@ -41,7 +41,6 @@ public class BukkitPlayer extends LocalPlayer {
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
this.player = player;
}
@ -52,6 +51,7 @@ public class BukkitPlayer extends LocalPlayer {
return itemStack != null ? itemStack.getTypeId() : 0;
}
@Override
public BaseBlock getBlockInHand() throws WorldEditException {
ItemStack itemStack = player.getItemInHand();
return BukkitUtil.toBlock(getWorld(), itemStack);

View File

@ -25,6 +25,7 @@ import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Preference;
import org.bukkit.Bukkit;
@ -33,6 +34,7 @@ import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.*;
@ -93,6 +95,28 @@ public class BukkitServerInterface extends ServerInterface {
return ret;
}
@Nullable
@Override
public Player matchPlayer(Player player) {
if (player instanceof BukkitPlayer) {
return player;
} else {
org.bukkit.entity.Player bukkitPlayer = server.getPlayerExact(player.getName());
return bukkitPlayer != null ? new BukkitPlayer(plugin, this, bukkitPlayer) : null;
}
}
@Nullable
@Override
public com.sk89q.worldedit.world.World matchWorld(com.sk89q.worldedit.world.World world) {
if (world instanceof BukkitWorld) {
return world;
} else {
World bukkitWorld = server.getWorld(world.getName());
return bukkitWorld != null ? new BukkitWorld(bukkitWorld) : null;
}
}
@Override
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();

View File

@ -1110,13 +1110,15 @@ public class BukkitWorld extends LocalWorld {
@Override
public boolean equals(Object other) {
World world = getWorld();
if (!(other instanceof BukkitWorld)) {
if (other == null) {
return false;
} else if ((other instanceof BukkitWorld)) {
return ((BukkitWorld) other).getWorld().equals(getWorld());
} else if (other instanceof com.sk89q.worldedit.world.World) {
return ((com.sk89q.worldedit.world.World) other).getName().equals(getName());
} else {
return false;
}
return ((BukkitWorld) other).getWorld().equals(world);
}
@Override

View File

@ -339,7 +339,7 @@ public class WorldEditPlugin extends JavaPlugin {
return wrapPlayer((Player) sender);
}
return new BukkitCommandSender(this, this.server, sender);
return new BukkitCommandSender(this, sender);
}
/**