Make sure all WorldEdit files are in the plugins/WorldEdit folder

This commit is contained in:
zml2008 2012-03-28 11:03:59 -07:00
parent a4895cbd5d
commit 73dbbbac9a
6 changed files with 93 additions and 33 deletions

View File

@ -21,23 +21,54 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.util.YAMLConfiguration; import com.sk89q.worldedit.util.YAMLConfiguration;
import org.apache.commons.io.FileUtils;
import java.util.logging.Logger; import java.io.File;
import java.io.IOException;
/** /**
* YAMLConfiguration but with setting for no op permissions. * YAMLConfiguration but with setting for no op permissions and plugin root data folder
*/ */
public class BukkitConfiguration extends YAMLConfiguration { public class BukkitConfiguration extends YAMLConfiguration {
public boolean noOpPermissions = false; public boolean noOpPermissions = false;
private final WorldEditPlugin plugin;
public BukkitConfiguration(YAMLProcessor config, Logger logger) { public BukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) {
super(config, logger); super(config, plugin.getLogger());
this.plugin = plugin;
} }
@Override @Override
public void load() { public void load() {
super.load(); super.load();
noOpPermissions = config.getBoolean("no-op-permissions", false); noOpPermissions = config.getBoolean("no-op-permissions", false);
migrateLegacyFolders();
}
private void migrateLegacyFolders() {
migrate(scriptsDir, "craftscripts");
migrate(saveDir, "schematics");
migrate("drawings", "draw.js images");
}
private void migrate(String file, String name) {
File fromDir = new File(".", file);
File toDir = new File(getWorkingDirectory(), file);
if (fromDir.exists() & !toDir.exists()) {
try {
FileUtils.moveDirectory(fromDir, toDir);
plugin.getLogger().info("Migrated " + name + " folder '" + file +
"' from server root to plugin data folder." );
} catch (IOException e) {
plugin.getLogger().warning("Error while migrating " + name + " folder: " +
e.getMessage());
}
}
}
@Override
public File getWorkingDirectory() {
return plugin.getDataFolder();
} }
} }

View File

@ -27,7 +27,6 @@ import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import com.sk89q.util.yaml.YAMLProcessor; import com.sk89q.util.yaml.YAMLProcessor;
@ -53,11 +52,6 @@ public class WorldEditPlugin extends JavaPlugin {
*/ */
public static final String CUI_PLUGIN_CHANNEL = "WECUI"; public static final String CUI_PLUGIN_CHANNEL = "WECUI";
/**
* WorldEdit messages get sent here.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/** /**
* The server interface that all server-related API goes through. * The server interface that all server-related API goes through.
*/ */
@ -100,7 +94,7 @@ public class WorldEditPlugin extends JavaPlugin {
// Set up configuration and such, including the permissions // Set up configuration and such, including the permissions
// resolver // resolver
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), logger); config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
PermissionsResolverManager.initialize(this); PermissionsResolverManager.initialize(this);
// Load the configuration // Load the configuration
@ -161,7 +155,7 @@ public class WorldEditPlugin extends JavaPlugin {
if (copy == null) throw new FileNotFoundException(); if (copy == null) throw new FileNotFoundException();
input = file.getInputStream(copy); input = file.getInputStream(copy);
} catch (IOException e) { } catch (IOException e) {
logger.severe(getDescription().getName() + ": Unable to read default configuration: " + name); getLogger().severe("Unable to read default configuration: " + name);
} }
if (input != null) { if (input != null) {
FileOutputStream output = null; FileOutputStream output = null;
@ -174,8 +168,7 @@ public class WorldEditPlugin extends JavaPlugin {
output.write(buf, 0, length); output.write(buf, 0, length);
} }
logger.info(getDescription().getName() getLogger().info("Default configuration file written: " + name);
+ ": Default configuration file written: " + name);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {

View File

@ -0,0 +1,41 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* 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.spout;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.worldedit.util.YAMLConfiguration;
import java.io.File;
import java.util.logging.Logger;
/**
* @author zml2008
*/
public class SpoutConfiguration extends YAMLConfiguration {
private final WorldEditPlugin plugin;
public SpoutConfiguration(YAMLProcessor config, WorldEditPlugin plugin) {
super(config, plugin.getLogger());
this.plugin = plugin;
}
@Override
public File getWorkingDirectory() {
return plugin.getDataFolder();
}
}

View File

@ -46,7 +46,7 @@ import java.util.regex.Pattern;
/** /**
* Handles all events thrown in relation to a Player * Handles all events thrown in relation to a Player
*/ */
public class WorldEditPlayerListener implements Listener { public class WorldEditListener implements Listener {
/** /**
* Plugin. * Plugin.
*/ */
@ -61,7 +61,7 @@ public class WorldEditPlayerListener implements Listener {
* *
* @param plugin * @param plugin
*/ */
public WorldEditPlayerListener(WorldEditPlugin plugin) { public WorldEditListener(WorldEditPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -49,10 +49,6 @@ import java.util.zip.ZipEntry;
* @author sk89q * @author sk89q
*/ */
public class WorldEditPlugin extends CommonPlugin implements Named { public class WorldEditPlugin extends CommonPlugin implements Named {
/**
* WorldEdit messages get sent here.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
/** /**
* The server interface that all server-related API goes through. * The server interface that all server-related API goes through.
@ -80,7 +76,7 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
final String pluginYmlVersion = getDescription().getVersion(); final String pluginYmlVersion = getDescription().getVersion();
final String manifestVersion = WorldEdit.getVersion(); final String manifestVersion = WorldEdit.getVersion();
logger.info("WorldEdit " + pluginYmlVersion + " enabled."); getLogger().info("WorldEdit " + pluginYmlVersion + " enabled.");
if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) { if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) {
WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")"); WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")");
} }
@ -93,7 +89,7 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
// Set up configuration and such, including the permissions // Set up configuration and such, including the permissions
// resolver // resolver
config = new YAMLConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), logger); config = new SpoutConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
// Load the configuration // Load the configuration
loadConfiguration(); loadConfiguration();
@ -136,7 +132,7 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
* Register the events used by WorldEdit. * Register the events used by WorldEdit.
*/ */
protected void registerEvents() { protected void registerEvents() {
getGame().getEventManager().registerEvents(new WorldEditPlayerListener(this), this); getGame().getEventManager().registerEvents(new WorldEditListener(this), this);
} }
/** /**
@ -155,7 +151,7 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
if (copy == null) throw new FileNotFoundException(); if (copy == null) throw new FileNotFoundException();
input = file.getInputStream(copy); input = file.getInputStream(copy);
} catch (IOException e) { } catch (IOException e) {
logger.severe(getDescription().getName() + ": Unable to read default configuration: " + name); getLogger().severe("Unable to read default configuration: " + name);
} }
if (input != null) { if (input != null) {
FileOutputStream output = null; FileOutputStream output = null;
@ -168,22 +164,19 @@ public class WorldEditPlugin extends CommonPlugin implements Named {
output.write(buf, 0, length); output.write(buf, 0, length);
} }
logger.info(getDescription().getName() getLogger().info("Default configuration file written: " + name);
+ ": Default configuration file written: " + name);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
if (input != null) { input.close();
input.close(); } catch (IOException ignore) {}
}
} catch (IOException e) {}
try { try {
if (output != null) { if (output != null) {
output.close(); output.close();
} }
} catch (IOException e) {} } catch (IOException ignore) {}
} }
} }
} }

View File

@ -25,6 +25,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LogFormat; import com.sk89q.worldedit.LogFormat;
import com.sk89q.worldedit.snapshots.SnapshotRepository; import com.sk89q.worldedit.snapshots.SnapshotRepository;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
@ -105,7 +106,8 @@ public class YAMLConfiguration extends LocalConfiguration {
String logFile = config.getString("logging.file", ""); String logFile = config.getString("logging.file", "");
if (!logFile.equals("")) { if (!logFile.equals("")) {
try { try {
logFileHandler = new FileHandler(logFile, true); logFileHandler = new FileHandler(new File(getWorkingDirectory(),
logFile).getAbsolutePath(), true);
logFileHandler.setFormatter(new LogFormat()); logFileHandler.setFormatter(new LogFormat());
logger.addHandler(logFileHandler); logger.addHandler(logFileHandler);
} catch (IOException e) { } catch (IOException e) {