2011-01-01 02:36:25 +00:00
|
|
|
// $Id$
|
|
|
|
/*
|
|
|
|
* WorldEdit
|
|
|
|
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
|
|
|
|
import java.io.File;
|
2011-01-17 10:52:57 +00:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2011-01-16 21:19:29 +00:00
|
|
|
import java.util.logging.Logger;
|
2011-01-01 02:36:25 +00:00
|
|
|
import org.bukkit.Server;
|
2011-01-22 02:24:38 +00:00
|
|
|
import org.bukkit.command.Command;
|
2011-01-16 21:19:29 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2011-01-01 02:36:25 +00:00
|
|
|
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;
|
2011-01-18 00:47:38 +00:00
|
|
|
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
|
|
|
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
2011-01-01 02:36:25 +00:00
|
|
|
import com.sk89q.worldedit.*;
|
|
|
|
|
2011-01-08 21:03:18 +00:00
|
|
|
/**
|
|
|
|
* Plugin for Bukkit.
|
|
|
|
*
|
|
|
|
* @author sk89qs
|
|
|
|
*/
|
2011-01-01 02:36:25 +00:00
|
|
|
public class WorldEditPlugin extends JavaPlugin {
|
2011-01-16 21:19:29 +00:00
|
|
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
public final ServerInterface server;
|
|
|
|
public final WorldEditController controller;
|
2011-01-16 17:39:11 +00:00
|
|
|
public final WorldEditAPI api;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-01-16 21:19:29 +00:00
|
|
|
private final LocalConfiguration config;
|
2011-01-18 00:47:38 +00:00
|
|
|
private final PermissionsResolverManager perms;
|
|
|
|
|
2011-01-01 02:36:25 +00:00
|
|
|
private final WorldEditPlayerListener playerListener =
|
|
|
|
new WorldEditPlayerListener(this);
|
|
|
|
private final WorldEditBlockListener blockListener =
|
|
|
|
new WorldEditBlockListener(this);
|
2011-01-18 00:47:38 +00:00
|
|
|
private final PermissionsResolverServerListener permsListener;
|
2011-01-01 02:36:25 +00:00
|
|
|
|
|
|
|
public WorldEditPlugin(PluginLoader pluginLoader, Server instance,
|
2011-01-16 17:39:11 +00:00
|
|
|
PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
|
|
|
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
2011-01-01 02:36:25 +00:00
|
|
|
|
2011-01-16 21:19:29 +00:00
|
|
|
logger.info("WorldEdit " + desc.getVersion() + " loaded.");
|
|
|
|
|
2011-01-17 10:52:57 +00:00
|
|
|
folder.mkdirs();
|
|
|
|
|
|
|
|
createDefaultConfiguration("config.yml");
|
|
|
|
|
2011-01-16 21:19:29 +00:00
|
|
|
config = new BukkitConfiguration(getConfiguration(), logger);
|
2011-01-18 00:47:38 +00:00
|
|
|
perms = new PermissionsResolverManager(getConfiguration(), getServer(),
|
|
|
|
"WorldEdit", logger);
|
|
|
|
permsListener = new PermissionsResolverServerListener(perms);
|
2011-01-16 21:19:29 +00:00
|
|
|
loadConfiguration();
|
|
|
|
|
2011-01-03 20:05:41 +00:00
|
|
|
server = new BukkitServerInterface(getServer());
|
|
|
|
controller = new WorldEditController(server, config);
|
2011-01-16 17:39:11 +00:00
|
|
|
api = new WorldEditAPI(this);
|
2011-01-01 03:28:28 +00:00
|
|
|
|
|
|
|
registerEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onEnable() {
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onDisable() {
|
|
|
|
controller.clearSessions();
|
|
|
|
}
|
|
|
|
|
2011-01-01 03:28:28 +00:00
|
|
|
private void registerEvents() {
|
2011-01-01 02:36:25 +00:00
|
|
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT,
|
|
|
|
playerListener, Priority.Normal, this);
|
2011-01-26 18:52:53 +00:00
|
|
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_ANIMATION,
|
|
|
|
playerListener, Priority.Normal, this);
|
2011-01-19 10:27:12 +00:00
|
|
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_ITEM,
|
|
|
|
playerListener, Priority.Normal, this);
|
2011-01-22 02:24:38 +00:00
|
|
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND,
|
|
|
|
playerListener, Priority.Normal, this);
|
2011-01-01 02:36:25 +00:00
|
|
|
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED,
|
|
|
|
blockListener, Priority.Normal, this);
|
2011-01-09 19:43:47 +00:00
|
|
|
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED,
|
2011-01-18 00:47:38 +00:00
|
|
|
blockListener, Priority.Normal, this);
|
|
|
|
|
|
|
|
permsListener.register(this);
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|
2011-01-16 17:39:11 +00:00
|
|
|
|
2011-01-17 10:52:57 +00:00
|
|
|
private void createDefaultConfiguration(String name) {
|
|
|
|
File actual = new File(getDataFolder(), name);
|
|
|
|
if (!actual.exists()) {
|
|
|
|
|
|
|
|
InputStream input =
|
|
|
|
WorldEditPlugin.class.getResourceAsStream("/defaults/" + name);
|
|
|
|
if (input != null) {
|
|
|
|
FileOutputStream output = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
output = new FileOutputStream(actual);
|
|
|
|
byte[] buf = new byte[8192];
|
|
|
|
int length = 0;
|
|
|
|
while ((length = input.read(buf)) > 0) {
|
|
|
|
output.write(buf, 0, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.info("WorldEdit: Default configuration file written: "
|
|
|
|
+ name);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (input != null)
|
|
|
|
input.close();
|
|
|
|
} catch (IOException e) {}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (output != null)
|
|
|
|
output.close();
|
|
|
|
} catch (IOException e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-16 21:19:29 +00:00
|
|
|
public void loadConfiguration() {
|
|
|
|
getConfiguration().load();
|
|
|
|
config.load();
|
|
|
|
perms.load();
|
|
|
|
}
|
|
|
|
|
2011-01-22 02:24:38 +00:00
|
|
|
public boolean onCommand(Player player, Command cmd, String commandLabel, String[] args) {
|
|
|
|
if (cmd.getName().equalsIgnoreCase("reloadwe")
|
|
|
|
&& hasPermission(player, "reloadwe")) {
|
|
|
|
try {
|
|
|
|
loadConfiguration();
|
|
|
|
player.sendMessage("WorldEdit configuration reloaded.");
|
|
|
|
} catch (Throwable t) {
|
|
|
|
player.sendMessage("Error while reloading: "
|
|
|
|
+ t.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] split = new String[args.length + 1];
|
|
|
|
System.arraycopy(args, 0, split, 1, args.length);
|
|
|
|
split[0] = "/" + cmd.getName();
|
|
|
|
|
2011-01-23 00:34:46 +00:00
|
|
|
controller.handleCommand(wrapPlayer(player), split);
|
|
|
|
|
|
|
|
return true;
|
2011-01-22 02:24:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 21:19:29 +00:00
|
|
|
String[] getGroups(Player player) {
|
|
|
|
return perms.getGroups(player.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean inGroup(Player player, String group) {
|
|
|
|
return perms.inGroup(player.getName(), group);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean hasPermission(Player player, String perm) {
|
2011-01-22 02:00:29 +00:00
|
|
|
return player.isOp() || perms.hasPermission(player.getName(), perm);
|
2011-01-16 21:19:29 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 02:24:38 +00:00
|
|
|
BukkitPlayer wrapPlayer(Player player) {
|
|
|
|
return new BukkitPlayer(this, this.server, player);
|
|
|
|
}
|
|
|
|
|
2011-01-16 17:39:11 +00:00
|
|
|
public WorldEditAPI getAPI() {
|
|
|
|
return api;
|
|
|
|
}
|
2011-01-01 02:36:25 +00:00
|
|
|
}
|