From ebf204cbc320fde2ddde220094141046ee6608c3 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 31 Dec 2010 18:36:25 -0800 Subject: [PATCH] Initial commit. --- build.xml | 1 + .../sk89q/worldedit/bukkit/BukkitPlayer.java | 122 +++++++++++++++ .../bukkit/BukkitServerInterface.java | 147 ++++++++++++++++++ .../bukkit/WorldEditBlockListener.java | 67 ++++++++ .../bukkit/WorldEditPlayerListener.java | 65 ++++++++ .../worldedit/bukkit/WorldEditPlugin.java | 85 ++++++++++ 6 files changed, 487 insertions(+) create mode 100644 src/com/sk89q/worldedit/bukkit/BukkitPlayer.java create mode 100644 src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java create mode 100644 src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java create mode 100644 src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java create mode 100644 src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java diff --git a/build.xml b/build.xml index 205c44da2..f18a9482e 100644 --- a/build.xml +++ b/build.xml @@ -21,6 +21,7 @@ + diff --git a/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java new file mode 100644 index 000000000..58d900039 --- /dev/null +++ b/src/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -0,0 +1,122 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bukkit; + +import org.bukkit.*; +import com.sk89q.worldedit.*; +import com.sk89q.worldedit.bags.BlockBag; + +public class BukkitPlayer extends WorldEditPlayer { + private Player player; + + public BukkitPlayer(Player player) { + this.player = player; + } + + @Override + public Vector getBlockTrace(int range) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Vector getSolidBlockTrace(int range) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getItemInHand() { + ItemStack itemStack = player.getSelectedItem(); + return itemStack != null ? itemStack.getTypeID() : 0; + } + + @Override + public String getName() { + return player.getName(); + } + + @Override + public Vector getPosition() { + Location loc = player.getLocation(); + return new Vector(loc.getX(), loc.getY(), loc.getZ()); + } + + @Override + public double getPitch() { + return player.getLocation().getPitch(); + } + + @Override + public double getYaw() { + return player.getLocation().getYaw(); + } + + @Override + public void giveItem(int type, int amt) { + // TODO Auto-generated method stub + + } + + @Override + public boolean passThroughForwardWall(int range) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void printRaw(String msg) { + player.sendMessage(msg); + } + + @Override + public void print(String msg) { + player.sendMessage(msg); + } + + @Override + public void printError(String msg) { + player.sendMessage(msg); + } + + @Override + public void setPosition(Vector pos, float pitch, float yaw) { + // TODO Auto-generated method stub + } + + @Override + public String[] getGroups() { + // TODO Auto-generated method stub + return null; + } + + @Override + public BlockBag getInventoryBlockBag() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean hasPermission(String perm) { + // TODO Auto-generated method stub + return true; + } + +} diff --git a/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java new file mode 100644 index 000000000..c997c620d --- /dev/null +++ b/src/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -0,0 +1,147 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bukkit; + +import org.bukkit.*; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.ServerInterface; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.blocks.BaseItemStack; + +public class BukkitServerInterface extends ServerInterface { + public Server server; + + public BukkitServerInterface(Server server) { + this.server = server; + } + + @Override + public boolean setBlockType(Vector pt, int type) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int getBlockType(Vector pt) { + return server.getWorlds()[0].getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getType(); + } + + @Override + public void setBlockData(Vector pt, int data) { + // TODO Auto-generated method stub + + } + + @Override + public int getBlockData(Vector pt) { + return server.getWorlds()[0].getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData(); + } + + @Override + public void setSignText(Vector pt, String[] text) { + // TODO Auto-generated method stub + + } + + @Override + public String[] getSignText(Vector pt) { + // TODO Auto-generated method stub + return null; + } + + @Override + public BaseItemStack[] getChestContents(Vector pt) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean setChestContents(Vector pt, BaseItemStack[] contents) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean clearChest(Vector pt) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isValidMobType(String type) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void setMobSpawnerType(Vector pt, String mobType) { + // TODO Auto-generated method stub + + } + + @Override + public String getMobSpawnerType(Vector pt) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean generateTree(EditSession editSession, Vector pt) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void dropItem(Vector pt, int type, int count, int times) { + // TODO Auto-generated method stub + + } + + @Override + public void dropItem(Vector pt, int type, int count) { + // TODO Auto-generated method stub + + } + + @Override + public void dropItem(Vector pt, int type) { + // TODO Auto-generated method stub + + } + + @Override + public void simulateBlockMine(Vector pt) { + // TODO Auto-generated method stub + + } + + @Override + public int resolveItem(String name) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int killMobs(Vector origin, int radius) { + // TODO Auto-generated method stub + return 0; + } + +} diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java b/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java new file mode 100644 index 000000000..d77f68a5c --- /dev/null +++ b/src/com/sk89q/worldedit/bukkit/WorldEditBlockListener.java @@ -0,0 +1,67 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bukkit; + +import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockBrokenEvent; +import org.bukkit.event.block.BlockRightClickedEvent; +import com.sk89q.worldedit.*; + +public class WorldEditBlockListener extends BlockListener { + /** + * Plugin. + */ + private WorldEditPlugin plugin; + + /** + * Construct the object; + * + * @param plugin + */ + public WorldEditBlockListener(WorldEditPlugin plugin) { + this.plugin = plugin; + } + + /** + * Called when a block is broken (or destroyed) + * + * @param event Relevant event details + */ + public void onBlockBroken(BlockBrokenEvent event) { + Vector pos = new Vector(event.getBlock().getX(), + event.getBlock().getY(), + event.getBlock().getZ()); + WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); + plugin.controller.handleBlockLeftClick(player, pos); + } + + /** + * Called when a player right clicks a block + * + * @param event Relevant event details + */ + public void onBlockRightClicked(BlockRightClickedEvent event) { + Vector pos = new Vector(event.getBlock().getX(), + event.getBlock().getY(), + event.getBlock().getZ()); + WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); + plugin.controller.handleBlockRightClick(player, pos); + } +} diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java b/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java new file mode 100644 index 000000000..e62c2c5b0 --- /dev/null +++ b/src/com/sk89q/worldedit/bukkit/WorldEditPlayerListener.java @@ -0,0 +1,65 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bukkit; + +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.event.player.PlayerListener; + +import com.sk89q.worldedit.WorldEditPlayer; + +/** + * Handles all events thrown in relation to a Player + */ +public class WorldEditPlayerListener extends PlayerListener { + /** + * Plugin. + */ + private WorldEditPlugin plugin; + + /** + * Construct the object; + * + * @param plugin + */ + public WorldEditPlayerListener(WorldEditPlugin plugin) { + this.plugin = plugin; + } + + /** + * Called when a player leaves a server + * + * @param event Relevant event details + */ + public void onPlayerQuit(PlayerEvent event) { + WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); + plugin.controller.handleDisconnect(player); + } + + /** + * Called when a player attempts to use a command + * + * @param event Relevant event details + */ + public void onPlayerCommand(PlayerChatEvent event) { + WorldEditPlayer player = new BukkitPlayer(plugin.getServer().getOnlinePlayers()[0]); + plugin.controller.handleCommand(player, event.getMessage().split(" ")); + } +} diff --git a/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java new file mode 100644 index 000000000..7ea755e92 --- /dev/null +++ b/src/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -0,0 +1,85 @@ +// $Id$ +/* + * WorldEdit + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldedit.bukkit; + +import java.io.File; +import java.util.HashSet; +import org.bukkit.Server; +import org.bukkit.event.Event.Priority; +import org.bukkit.event.Event; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginLoader; +import org.bukkit.plugin.java.JavaPlugin; +import com.sk89q.worldedit.*; + +public class WorldEditPlugin extends JavaPlugin { + public final WorldEditController controller = + new WorldEditController(); + + private final WorldEditPlayerListener playerListener = + new WorldEditPlayerListener(this); + private final WorldEditBlockListener blockListener = + new WorldEditBlockListener(this); + + public WorldEditPlugin(PluginLoader pluginLoader, Server instance, + PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { + super(pluginLoader, instance, desc, plugin, cLoader); + + registerEvents(); + } + + public void onEnable() { + //loadConfiguration(); + + ServerInterface.setup(new BukkitServerInterface(getServer())); + + controller.profile = true; + controller.allowedBlocks = new HashSet(); + controller.defaultChangeLimit = -1; + controller.maxChangeLimit = -1; + controller.shellSaveType = "sh"; + controller.snapshotRepo = null; + controller.maxRadius = -1; + controller.maxSuperPickaxeSize = 5; + controller.logComands = false; + controller.registerHelp = true; + controller.wandItem = 271; + controller.superPickaxeDrop = true; + controller.superPickaxeManyDrop = true; + controller.noDoubleSlash = true; + controller.useInventory = false; + controller.useInventoryOverride = false; + } + + public void onDisable() { + controller.clearSessions(); + } + + private void registerEvents() { + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, + playerListener, Priority.Normal, this); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, + playerListener, Priority.Normal, this); + getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED, + blockListener, Priority.Normal, this); + getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED, + blockListener, Priority.Normal, this); + } +}